File tree Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Expand file tree Collapse file tree 4 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -390,6 +390,8 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
390
390
391
391
bool isCanonicalTypeInContext (Type type) const ;
392
392
393
+ bool isValidTypeInContext (Type type) const ;
394
+
393
395
// / Retrieve the conformance access path used to extract the conformance of
394
396
// / interface \c type to the given \c protocol.
395
397
// /
Original file line number Diff line number Diff line change @@ -466,6 +466,19 @@ CanType GenericSignatureImpl::getCanonicalTypeInContext(Type type) const {
466
466
type, { })->getCanonicalType ();
467
467
}
468
468
469
+ bool GenericSignatureImpl::isValidTypeInContext (Type type) const {
470
+ auto &ctx = getASTContext ();
471
+ switch (ctx.LangOpts .EnableRequirementMachine ) {
472
+ case RequirementMachineMode::Disabled:
473
+ llvm::errs () << " Not implemented\n " ;
474
+ abort ();
475
+
476
+ case RequirementMachineMode::Enabled:
477
+ case RequirementMachineMode::Verify:
478
+ return getRequirementMachine ()->isValidTypeInContext (type);
479
+ }
480
+ }
481
+
469
482
ArrayRef<CanTypeWrapper<GenericTypeParamType>>
470
483
CanGenericSignature::getGenericParams () const {
471
484
auto params = getPointer ()->getGenericParams ().getOriginalArray ();
Original file line number Diff line number Diff line change @@ -431,6 +431,19 @@ Type RequirementMachine::getCanonicalTypeInContext(
431
431
});
432
432
}
433
433
434
+ // / Determine if the given type parameter is valid with respect to this
435
+ // / requirement machine's generic signature.
436
+ bool RequirementMachine::isValidTypeInContext (Type type) const {
437
+ assert (type->isTypeParameter ());
438
+
439
+ auto term = Context.getMutableTermForType (type->getCanonicalType (),
440
+ /* proto=*/ nullptr );
441
+ System.simplify (term);
442
+
443
+ auto prefix = getLongestValidPrefix (term);
444
+ return (prefix == term);
445
+ }
446
+
434
447
// / Retrieve the conformance access path used to extract the conformance of
435
448
// / interface \c type to the given \c protocol.
436
449
// /
Original file line number Diff line number Diff line change @@ -129,6 +129,7 @@ class RequirementMachine final {
129
129
bool isCanonicalTypeInContext (Type type) const ;
130
130
Type getCanonicalTypeInContext (Type type,
131
131
TypeArrayView<GenericTypeParamType> genericParams) const ;
132
+ bool isValidTypeInContext (Type type) const ;
132
133
ConformanceAccessPath getConformanceAccessPath (Type type,
133
134
ProtocolDecl *protocol);
134
135
TypeDecl *lookupNestedType (Type depType, Identifier name) const ;
You can’t perform that action at this time.
0 commit comments