Commit Graph

14 Commits

Author SHA1 Message Date
Slava Pestov
36c49ea9d6 AST: Allow substitution limits >= 32767 2025-08-20 12:26:38 -04:00
Slava Pestov
4eaa7e3b47 AST: Add -max-substitution-count= and -max-substitution-depth= frontend flags 2025-07-18 20:03:03 -04:00
Slava Pestov
8d05d79fad AST: Cache substituted substitution maps inside the InFlightSubstitution
A substitution map contains conformances, and a conformance can contain
a substitution map. This will always be a DAG, but not a tree, and to
avoid exponential blowup in certain edge cases, let's cache the work to
avoid visiting the same substitution map repeatedly, if multiple
conformances refer to the same substitution map.
2025-07-18 20:03:03 -04:00
Slava Pestov
103428fe80 AST: More robust recursion check for opaque types with infinite underlying types
Tracking seen declarations and substitution maps only detects the
situation where the opaque type's underlying type contains itself
with the same substitution map. However, it is also possible to
recurse with a different substitution map.

In general termination is undecidable with a problem like this,
so instead of trying to catch cycles, just impose a termination
limit.

This converts a stack overflow into an assertion, which is still
not ideal; we should really diagnose something instead. But this
is a first step.
2025-07-18 20:03:03 -04:00
Slava Pestov
ef0164dcbd AST: Small cleanup for InFlightSubstitution 2025-07-18 19:12:33 -04:00
Slava Pestov
0b961c6139 AST: Clean up InFlightSubstitution::lookupConformance()
The special handling of DynamicSelfType should no longer be necessary
so I'm removing it.
2025-04-28 13:48:24 -04:00
Slava Pestov
593358add1 AST: Type substitution can skip subtrees that won't change 2024-09-01 12:50:17 -04:00
Slava Pestov
da4d076f02 AST: Introduce SubstFlags::SubstitutePrimaryArchetypes 2024-08-22 18:41:14 -04:00
Slava Pestov
39b4bda1dc AST: Introduce SubstFlags::SubstituteLocalArchetypes 2024-08-21 14:23:37 -04:00
Slava Pestov
be218f5e16 AST: Use PackElementType to model references to pack elements of outer expansions 2023-06-06 14:18:37 -04:00
John McCall
c041d1061a Perform component-wise substitution of pack expansions immediately.
Substitution of a pack expansion type may now produce a pack type.
We immediately expand that pack when transforming a tuple, a function
parameter, or a pack.

I had to duplicate the component-wise transformation logic in the
simplifyType transform, which I'm not pleased about, but a little
code duplication seemed a lot better than trying to unify the code
in two very different places.

I think we're very close to being able to assert that pack expansion
shapes are either pack archetypes or pack parameters; unfortunately,
the pack matchers intentionally produce expansions of packs, and I
didn't want to add that to an already-large patch.
2023-03-26 04:12:59 -04:00
John McCall
1042955d59 [NFC] Add an operation to change the current options on NFC 2023-03-25 18:54:14 -04:00
John McCall
4edfd79fc9 [NFC] Add a convenience function to IFS 2023-03-25 18:54:14 -04:00
John McCall
80551ce8ad [NFC] Thread a common type through all the AST substitution code.
There are a lot of problems caused by our highly-abstract substitution
subsystem.  Most of them would be solved by a more semantic / holistic
understanding of the active transformation, but that's difficult to do
because we just pass around function_refs.  The first step in fixing
that is to pass around a better currency type.  For now, it can just
hold the function_refs (and the SubstOptions).

I've set it up so that the places that just apply SubstitutionMaps
are constructing the IFS in a standard way; that should make it easy
to change those places in the future.
2023-03-25 18:54:14 -04:00