@@ -85,6 +85,13 @@ class OpEvalImpl {
8585 return V;
8686 }
8787
88+ // Get a value for pattern matching
89+ // that can ignore syntax closures
90+ // (which does not include symbols.)
91+ heavy::Value getPatternValue (mlir::Value M) {
92+ return Context.UnwrapSyntaxClosure (getValue (M));
93+ }
94+
8895 static heavy::SourceLocation getSourceLocation (mlir::Location Loc) {
8996 return heavy::SourceLocation (mlir::OpaqueLoc
9097 ::getUnderlyingLocationOrNull<heavy::SourceLocationEncoding*>(Loc));
@@ -674,7 +681,7 @@ class OpEvalImpl {
674681
675682 BlockItrTy Visit (MatchOp Op) {
676683 heavy::Value P = Op.getVal ().getValue (Context);
677- heavy::Value E = getValue (Op.getInput ());
684+ heavy::Value E = getPatternValue (Op.getInput ());
678685 heavy::EnvEntry Entry;
679686 if (isIdentifier (E) && isIdentifier (P)) {
680687 // If the symbol is in the environment we can skip
@@ -699,7 +706,7 @@ class OpEvalImpl {
699706 }
700707
701708 BlockItrTy Visit (MatchPairOp Op) {
702- heavy::Value E = getValue (Op.getInput ());
709+ heavy::Value E = getPatternValue (Op.getInput ());
703710 if (auto * Pair = dyn_cast<heavy::Pair>(E)) {
704711 setValue (Op.getCar (), Pair->Car );
705712 setValue (Op.getCdr (), Pair->Cdr );
@@ -712,7 +719,7 @@ class OpEvalImpl {
712719 BlockItrTy Visit (MatchTailOp Op) {
713720 // Here we include the last cdr in the length
714721 // of a list proper or improper.
715- heavy::Value E = getValue (Op.getInput ());
722+ heavy::Value E = getPatternValue (Op.getInput ());
716723 uint32_t TargetLen = Op.getLength ();
717724 assert (TargetLen >= 1 && " expecting positive length" );
718725 uint32_t TotalLen = 1 ;
@@ -828,7 +835,7 @@ class OpEvalImpl {
828835 break ;
829836 auto Scope = ValueMapScope (ValueMap);
830837 BlockItrTy Itr = Op.getBody ().front ().begin ();
831- setValue (BodyArg, Pair-> Car );
838+ setValue (BodyArg, Pair);
832839 while (Itr != BlockItrTy () && Itr != BlockItrTy (Op))
833840 Itr = Visit (&*Itr);
834841 // Check subpattern failure.
@@ -846,6 +853,7 @@ class OpEvalImpl {
846853 }
847854
848855 BlockItrTy Visit (ResolveOp Op) {
856+ heavy::SourceLocation Loc = getSourceLocation (Op.getLoc ());
849857 if (auto ParentOp = dyn_cast<SubpatternOp>(Op->getParentOp ())) {
850858 // We are at the terminator of a subpattern body region.
851859 assert (ParentOp.getPacks ().size () ==
@@ -856,7 +864,7 @@ class OpEvalImpl {
856864 // Construct each pack as a reversed ordered list.
857865 for (unsigned i = 0 ; i < ResolveArgs.size (); i++) {
858866 Value Pack = Context.CreatePair (getValue (ResolveArgs[i]),
859- getValue (MResults[i]));
867+ getValue (MResults[i]), Loc );
860868 setValueParentScope (MResults[i], Pack);
861869 }
862870 return BlockItrTy ();
@@ -866,7 +874,8 @@ class OpEvalImpl {
866874 assert (Op.getArgs ().size () == 1 && " expecting single result" );
867875 heavy::Value CurrentResult = getValue (Op.getArgs ().front ());
868876 heavy::Value Result = Context.CreatePair (CurrentResult,
869- getValue (ExpandPacksOp.getResult ()));
877+ getValue (ExpandPacksOp.getResult ()),
878+ Loc);
870879 setValueParentScope (ExpandPacksOp.getResult (), Result);
871880 return BlockItrTy ();
872881 }
@@ -882,9 +891,11 @@ class OpEvalImpl {
882891
883892 BlockItrTy Visit (SyntaxClosureOp Op) {
884893 // Create a SyntaxClosure with the provided env argument.
894+ heavy::Value SourceVal = getValue (Op.getSourceVal ());
895+ heavy::SourceLocation Loc = SourceVal.getSourceLocation ();
885896 heavy::Value Input = getValue (Op.getInput ());
886897 heavy::Value Env = getValue (Op.getEnv ());
887- Value SC = Context.CreateSyntaxClosure (Context. getLoc () , Input, Env);
898+ Value SC = Context.CreateSyntaxClosure (Loc , Input, Env);
888899 setValue (Op.getResult (), SC);
889900
890901 return next (Op);
@@ -921,7 +932,8 @@ class OpEvalImpl {
921932 }
922933
923934 BlockItrTy Visit (SourceLocOp Op) {
924- heavy::SourceLocation Loc = getSourceLocation (Op.getLoc ());
935+ heavy::Value Arg = getValue (Op.getArg ());
936+ heavy::SourceLocation Loc = Arg.getSourceLocation ();
925937 heavy::Value V = Context.CreateSourceValue (Loc);
926938 setValue (Op.getResult (), V);
927939 return next (Op);
0 commit comments