@@ -157,13 +157,20 @@ namespace swift {
157157 llvm::DenseMap<SILBasicBlock*,
158158 Located<Identifier>> UndefinedBlocks;
159159
160+ // / The set of opened packs in the function, indexed by UUID.
161+ // / Note that we don't currently support parsing references to
162+ // / opened packs prior to their instruction, although this is
163+ // / theoretically possible if basic blocks are not sorted in
164+ // / dominance order.
165+ SILTypeResolutionContext::OpenedPackElementsMap OpenedPackElements;
166+
160167 // / Data structures used to perform name lookup for local values.
161168 llvm::StringMap<ValueBase*> LocalValues;
162169 llvm::StringMap<SourceLoc> ForwardRefLocalValues;
163170
164171 Type performTypeResolution (TypeRepr *TyR, bool IsSILType,
165172 GenericSignature GenericSig,
166- GenericParamList *GenericParams) const ;
173+ GenericParamList *GenericParams);
167174
168175 void convertRequirements (ArrayRef<RequirementRepr> From,
169176 SmallVectorImpl<Requirement> &To,
@@ -1253,11 +1260,12 @@ static bool parseDeclSILOptional(bool *isTransparent,
12531260
12541261Type SILParser::performTypeResolution (TypeRepr *TyR, bool IsSILType,
12551262 GenericSignature GenericSig,
1256- GenericParamList *GenericParams) const {
1263+ GenericParamList *GenericParams) {
12571264 if (!GenericSig)
12581265 GenericSig = ContextGenericSig;
12591266
1260- SILTypeResolutionContext SILContext (IsSILType, GenericParams);
1267+ SILTypeResolutionContext SILContext (IsSILType, GenericParams,
1268+ &OpenedPackElements);
12611269
12621270 return swift::performTypeResolution (TyR, P.Context , GenericSig,
12631271 &SILContext, &P.SF );
@@ -3408,7 +3416,18 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
34083416 auto openedEnv = GenericEnvironment::forOpenedElement (openedElementSig,
34093417 uuid, shapeClass, openedSubMap);
34103418
3411- ResultVal = B.createOpenPackElement (InstLoc, Val, openedEnv);
3419+ auto openInst = B.createOpenPackElement (InstLoc, Val, openedEnv);
3420+ ResultVal = openInst;
3421+
3422+ auto &entry = OpenedPackElements[uuid];
3423+ if (entry.DefinitionPoint .isValid ()) {
3424+ P.diagnose (OpcodeLoc, diag::multiple_open_pack_element);
3425+ P.diagnose (entry.DefinitionPoint , diag::sil_previous_instruction);
3426+ } else {
3427+ entry.DefinitionPoint = OpcodeLoc;
3428+ entry.Params = openedGenerics;
3429+ entry.Environment = openedEnv;
3430+ }
34123431 break ;
34133432 }
34143433
@@ -7593,7 +7612,8 @@ static bool parseSILWitnessTableEntry(
75937612 return true ;
75947613
75957614 SILTypeResolutionContext silContext (/* isSILType=*/ false ,
7596- witnessParams);
7615+ witnessParams,
7616+ /* openedPacks=*/ nullptr );
75977617 auto Ty =
75987618 swift::performTypeResolution (TyR.get (), P.Context ,
75997619 witnessSig, &silContext,
@@ -7657,7 +7677,8 @@ static bool parseSILWitnessTableEntry(
76577677 return true ;
76587678
76597679 SILTypeResolutionContext silContext (/* isSILType=*/ false ,
7660- witnessParams);
7680+ witnessParams,
7681+ /* openedPacks=*/ nullptr );
76617682 auto Ty =
76627683 swift::performTypeResolution (TyR.get (), P.Context ,
76637684 witnessSig, &silContext,
0 commit comments