Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split up typer context #11534

Merged
merged 27 commits into from
Feb 2, 2024
Merged

Split up typer context #11534

merged 27 commits into from
Feb 2, 2024

Conversation

Simn
Copy link
Member

@Simn Simn commented Feb 1, 2024

One of the things I always found difficult to reason about is our typer structure. The combination of many mutable fields, a rather subtle cloning mechanism and the delayed nature of the overall typing makes our internal structure brittle and error-prone. This PR doesn't necessarily change that, but at least it lays some groundwork.

Instead of having all fields on typer directly, we now work with a much smaller structure:

and typer = {
	com : context;
	t : basic_types;
	g : typer_globals;
	mutable m : typer_module;
	c : typer_class;
	f : typer_field;
	mutable e : typer_expr;
	mutable pass : typer_pass;
	mutable type_params : type_params;
	memory_marker : float array;
}

The basic idea is this:

  • The general ctx only knows ctx.g.
  • When typing a module, we clone the general context and initialize ctx.m accordingly
  • When typing a class, we clone the module context and initialize ctx.c properly
  • When typing a field, we clone the class context and initialize ctx.f properly
  • At expression-level, ctx.e is mutated to manage the per-expression state. Unlike ctx.f, this is re-initialized when typing local functions.
  • The only other data still on typer itself is the current pass, and the current type parameters. I'd like to look into splitting up the latter into type/field type parameters as well because I see no reason to merge these together.

There should be no observable changes from this PR, but there probably will be.

@Simn
Copy link
Member Author

Simn commented Feb 2, 2024

Ultimately, I'd like to see if we can make ctx.pass immutable, or perhaps even remove it entirely. The only reason it exists is to answer the "do we need fields?" question, which isn't being asked in too many places anymore. Related issue is #6567.

I'll merge this as-is though because the nature of the diff here makes this impossible to review otherwise.

Simn added 2 commits February 2, 2024 09:55
because that will totally fix something
@skial skial mentioned this pull request Feb 2, 2024
1 task
@Simn
Copy link
Member Author

Simn commented Feb 2, 2024

Holding back because we've come across a problem in some castledb generated code which we'll hopefully be able to figure out.

Simn and others added 4 commits February 2, 2024 11:06
and random cleanup
# Conflicts:
#	src/typing/typeload.ml
#	src/typing/typeloadModule.ml
@Simn Simn merged commit 2b0e8ce into development Feb 2, 2024
122 checks passed
@kLabz kLabz deleted the typecore_revolution branch May 28, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants