-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Make the DeclarationEngine
a lazy_static
as a semi-temporary bandaid
#2675
Conversation
The more that we lean into and depend on these global APIs, the trickier it's going to be to untangle their use throughout semantic analysis (
I think part of the issue here might be that we're talking about equivalence of the underlying declarations, and not the IDs themselves. I think we should be careful not to confuse the two. Perhaps we could consider a 3rd option: rather than using a In the described case, we can't know if two declarations referred to by two separate IDs are equivalent without access to the |
Per #2637 (comment), many standard traits like
PartialEq
need to be special-cased forDeclarationId
because eachDeclarationId
needs to index into theDeclarationEngine
(much the same asTypeEngine
andTypeId
). Of course, the standard traits likePartialEq
don't allow for extra arguments, so we have to come up with another solution.We could either:
CompileWrapper<'a, T>
that takes a&'a T
and&'a DeclarationEngine
, for exampleCompileWrapper<'a, DeclarationId>
. Then implementPartialEq
onCompileWrapper<'a, DeclarationId>
. The downside of this is that it introduces a layer of indirection in the compiler (draft branch here: https://github.com/FuelLabs/sway/tree/emilyaherbert/add-partial-eq)DeclarationId
a&'de DeclarationEngine
field so that we can implementPartialEq
onDeclarationId
directly, meaning thatDeclarationId
would then require a lifetime annotationDeclarationId<'de>
. The downside of this is that it requires the lifetime annotation to bubble up through everything thatDeclarationId<'de>
touches---includingTypedExpression
,TypeInfo
, etc. (draft branch here: https://github.com/FuelLabs/sway/tree/emilyaherbert/update-declaration-wrapper)Both of these are big PRs that will take some time to introduce and will create a blocker to the
DeclarationEngine
. So, I propose that we move theDeclarationEngine
to being alazy_static
(similar to theTypeEngine
). Then, in the future if/when we remove thelazy_static
implementation ofTypeEngine
, we can do the same operation forDeclarationEngine
.