@@ -414,17 +414,6 @@ struct ASTContext::Implementation {
414
414
llvm::FoldingSet<LayoutConstraintInfo> LayoutConstraints;
415
415
llvm::FoldingSet<OpaqueTypeArchetypeType> OpaqueArchetypes;
416
416
417
- llvm::FoldingSet<GenericSignatureImpl> GenericSignatures;
418
-
419
- // / Stored generic signature builders for canonical generic signatures.
420
- llvm::DenseMap<GenericSignature, std::unique_ptr<GenericSignatureBuilder>>
421
- GenericSignatureBuilders;
422
-
423
- // / Stored requirement machines for canonical generic signatures.
424
- llvm::DenseMap<GenericSignature,
425
- std::unique_ptr<rewriting::RequirementMachine>>
426
- RequirementMachines;
427
-
428
417
// / The set of function types.
429
418
llvm::FoldingSet<FunctionType> FunctionTypes;
430
419
@@ -485,6 +474,12 @@ struct ASTContext::Implementation {
485
474
llvm::FoldingSet<AutoDiffDerivativeFunctionIdentifier>
486
475
AutoDiffDerivativeFunctionIdentifiers;
487
476
477
+ llvm::FoldingSet<GenericSignatureImpl> GenericSignatures;
478
+
479
+ // / Stored generic signature builders for canonical generic signatures.
480
+ llvm::DenseMap<GenericSignature, std::unique_ptr<GenericSignatureBuilder>>
481
+ GenericSignatureBuilders;
482
+
488
483
// / A cache of information about whether particular nominal types
489
484
// / are representable in a foreign language.
490
485
llvm::DenseMap<NominalTypeDecl *, ForeignRepresentationInfo>
@@ -542,6 +537,14 @@ struct ASTContext::Implementation {
542
537
543
538
// / Memory allocation arena for the term rewriting system.
544
539
std::unique_ptr<rewriting::RewriteContext> TheRewriteContext;
540
+
541
+ // / Stored requirement machines for canonical generic signatures.
542
+ // /
543
+ // / This should come after TheRewriteContext above, since various destructors
544
+ // / compile stats in the histograms stored in our RewriteContext.
545
+ llvm::DenseMap<GenericSignature,
546
+ std::unique_ptr<rewriting::RequirementMachine>>
547
+ RequirementMachines;
545
548
};
546
549
547
550
ASTContext::Implementation::Implementation ()
@@ -1839,28 +1842,14 @@ void ASTContext::addLoadedModule(ModuleDecl *M) {
1839
1842
getImpl ().LoadedModules [M->getName ()] = M;
1840
1843
}
1841
1844
1842
- static AllocationArena getArena (GenericSignature genericSig) {
1843
- if (!genericSig)
1844
- return AllocationArena::Permanent;
1845
-
1846
- if (genericSig.hasTypeVariable ()) {
1847
- assert (false && " Unsubstituted type variable leaked into generic signature" );
1848
- return AllocationArena::ConstraintSolver;
1849
- }
1850
-
1851
- return AllocationArena::Permanent;
1852
- }
1853
-
1854
1845
void ASTContext::registerGenericSignatureBuilder (
1855
1846
GenericSignature sig,
1856
1847
GenericSignatureBuilder &&builder) {
1857
1848
if (LangOpts.EnableRequirementMachine == RequirementMachineMode::Enabled)
1858
1849
return ;
1859
1850
1860
1851
auto canSig = sig.getCanonicalSignature ();
1861
- auto arena = getArena (sig);
1862
- auto &genericSignatureBuilders =
1863
- getImpl ().getArena (arena).GenericSignatureBuilders ;
1852
+ auto &genericSignatureBuilders = getImpl ().GenericSignatureBuilders ;
1864
1853
auto known = genericSignatureBuilders.find (canSig);
1865
1854
if (known != genericSignatureBuilders.end ()) {
1866
1855
++NumRegisteredGenericSignatureBuildersAlready;
@@ -1882,9 +1871,7 @@ GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
1882
1871
1883
1872
// Check whether we already have a generic signature builder for this
1884
1873
// signature and module.
1885
- auto arena = getArena (sig);
1886
- auto &genericSignatureBuilders =
1887
- getImpl ().getArena (arena).GenericSignatureBuilders ;
1874
+ auto &genericSignatureBuilders = getImpl ().GenericSignatureBuilders ;
1888
1875
auto known = genericSignatureBuilders.find (sig);
1889
1876
if (known != genericSignatureBuilders.end ())
1890
1877
return known->second .get ();
@@ -1962,16 +1949,13 @@ GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
1962
1949
1963
1950
rewriting::RequirementMachine *
1964
1951
ASTContext::getOrCreateRequirementMachine (CanGenericSignature sig) {
1965
- assert (!sig.hasTypeVariable ());
1966
-
1967
1952
auto &rewriteCtx = getImpl ().TheRewriteContext ;
1968
1953
if (!rewriteCtx)
1969
1954
rewriteCtx.reset (new rewriting::RewriteContext (*this ));
1970
1955
1971
1956
// Check whether we already have a requirement machine for this
1972
1957
// signature.
1973
- auto arena = getArena (sig);
1974
- auto &machines = getImpl ().getArena (arena).RequirementMachines ;
1958
+ auto &machines = getImpl ().RequirementMachines ;
1975
1959
1976
1960
auto &machinePtr = machines[sig];
1977
1961
if (machinePtr) {
@@ -2003,8 +1987,7 @@ bool ASTContext::isRecursivelyConstructingRequirementMachine(
2003
1987
if (!rewriteCtx)
2004
1988
return false ;
2005
1989
2006
- auto arena = getArena (sig);
2007
- auto &machines = getImpl ().getArena (arena).RequirementMachines ;
1990
+ auto &machines = getImpl ().RequirementMachines ;
2008
1991
2009
1992
auto found = machines.find (sig);
2010
1993
if (found == machines.end ())
@@ -4489,21 +4472,21 @@ GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
4489
4472
assert (!params.empty ());
4490
4473
4491
4474
#ifndef NDEBUG
4492
- for (auto req : requirements)
4475
+ for (auto req : requirements) {
4493
4476
assert (req.getFirstType ()->isTypeParameter ());
4477
+ assert (!req.getFirstType ()->hasTypeVariable ());
4478
+ assert (req.getKind () == RequirementKind::Layout ||
4479
+ !req.getSecondType ()->hasTypeVariable ());
4480
+ }
4494
4481
#endif
4495
4482
4496
4483
// Check for an existing generic signature.
4497
4484
llvm::FoldingSetNodeID ID;
4498
4485
GenericSignatureImpl::Profile (ID, params, requirements);
4499
4486
4500
- auto arena = GenericSignature::hasTypeVariable (requirements)
4501
- ? AllocationArena::ConstraintSolver
4502
- : AllocationArena::Permanent;
4503
-
4504
4487
auto &ctx = getASTContext (params, requirements);
4505
4488
void *insertPos;
4506
- auto &sigs = ctx.getImpl ().getArena (arena). GenericSignatures ;
4489
+ auto &sigs = ctx.getImpl ().GenericSignatures ;
4507
4490
if (auto *sig = sigs.FindNodeOrInsertPos (ID, insertPos)) {
4508
4491
if (isKnownCanonical)
4509
4492
sig->CanonicalSignatureOrASTContext = &ctx;
@@ -4518,7 +4501,7 @@ GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
4518
4501
void *mem = ctx.Allocate (bytes, alignof (GenericSignatureImpl));
4519
4502
auto *newSig =
4520
4503
new (mem) GenericSignatureImpl (params, requirements, isKnownCanonical);
4521
- ctx.getImpl ().getArena (arena). GenericSignatures .InsertNode (newSig, insertPos);
4504
+ ctx.getImpl ().GenericSignatures .InsertNode (newSig, insertPos);
4522
4505
return newSig;
4523
4506
}
4524
4507
0 commit comments