Skip to content

red-knot(Salsa): Types without refinements#11899

Merged
MichaReiser merged 6 commits intomainfrom
salsa-8-types
Jun 20, 2024
Merged

red-knot(Salsa): Types without refinements#11899
MichaReiser merged 6 commits intomainfrom
salsa-8-types

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Jun 17, 2024

Summary

This PR ports the type inference code from red-knot to a salsa based implementation.

The biggest difference to the implementation in red-knot is that the type inference is per scope and not per expression, similar to how we build symbol tables.

This PR adds automatic type invalidation when types of dependency changes; this is a functionality that the implementation in the red knot crate doesn't support today.

Not yet ported

This PR does not yet implement type narrowing based on the control flow graph because the salsa version doesn't have a control flow graph yet.

Tests

I ported the existing tests of the red-knot code base that aren't context sensitive. I added a few new tests that validate that local changes don't trigger cross-file invalidation.

@MichaReiser MichaReiser changed the base branch from main to salsa-7-symbol-table June 17, 2024 12:20
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Jun 17, 2024
@MichaReiser MichaReiser requested a review from carljm June 18, 2024 11:23
@github-actions
Copy link
Contributor

github-actions bot commented Jun 18, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser marked this pull request as ready for review June 18, 2024 12:04
@MichaReiser MichaReiser force-pushed the salsa-7-symbol-table branch 2 times, most recently from 471d853 to 915b793 Compare June 18, 2024 12:31
Base automatically changed from salsa-7-symbol-table to main June 18, 2024 13:10
Copy link
Contributor

@carljm carljm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whole, this looks really good to me. A lot of things are cleaner and clearer than in the previous version. I am definitely learning to write better Rust from seeing how you rewrite my code :)

I think the most concerning comment here (in the sense of "might have significant implications for needing to revisit this architecture") is the one about cycles and the need to support multiple partially-completed scopes at once.

Comment on lines +768 to +772
class Base:
pass

class Sub(Base):
pass"#,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per my follow-up comment on the symbol table PR, I'm not convinced by the text-offsets argument, and I'd still rather use dedent in tests (unless we don't need it? see below) instead of this style of indentation for multi-line code in tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced by the text-offsets argument,

Wait until you have to debug some more byte offset errors, but maybe it's different in the type checker context. Debugging byte offsets was something I did frequently when working on the formatter.

I personally find both about equally ugly because rustfmt can't format them for you. But I'm not sure if I like having dedent calls in all tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't want dedent calls in every test. I'd want helpers for writing file contents in tests with less boilerplate, which would also call dedent on the given source.

And yeah, I think caring about byte offsets will be a lot less common in these tests than in parser or formatter tests.

@MichaReiser
Copy link
Member Author

I haven't yet found a solution for the cyclic import problem but Carl and I discussed that we don't think that this should block this PR. It seems there are a few different solutions to it, but they all require extending Salsa's functionality. See https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/Handling.20cyclic.20imports

Let's solve the dedent and testing functionality problem separately

@MichaReiser MichaReiser changed the title red-knot [salsa part 8]: Types without refinements red-knot(Salsa): Types without refinements Jun 20, 2024
@MichaReiser MichaReiser merged commit 22733cb into main Jun 20, 2024
@MichaReiser MichaReiser deleted the salsa-8-types branch June 20, 2024 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants