@@ -79,7 +79,7 @@ MaybeResult<IRBuilder::HoistedVal> IRBuilder::hoistLastValue() {
7979 if (type == Type::unreachable) {
8080 // Make sure the top of the stack also has an unreachable expression.
8181 if (stack.back ()->type != Type::unreachable) {
82- push (builder.makeUnreachable ());
82+ pushSynthetic (builder.makeUnreachable ());
8383 }
8484 return HoistedVal{Index (index), nullptr };
8585 }
@@ -88,7 +88,7 @@ MaybeResult<IRBuilder::HoistedVal> IRBuilder::hoistLastValue() {
8888 CHECK_ERR (scratchIdx);
8989 expr = builder.makeLocalSet (*scratchIdx, expr);
9090 auto * get = builder.makeLocalGet (*scratchIdx, type);
91- push (get);
91+ pushSynthetic (get);
9292 return HoistedVal{Index (index), get};
9393}
9494
@@ -107,7 +107,7 @@ Result<> IRBuilder::packageHoistedValue(const HoistedVal& hoisted,
107107 scope.exprStack .end ());
108108 auto * block = builder.makeBlock (exprs, type);
109109 scope.exprStack .resize (hoisted.valIndex );
110- push (block);
110+ pushSynthetic (block);
111111 };
112112
113113 auto type = scope.exprStack .back ()->type ;
@@ -137,33 +137,37 @@ Result<> IRBuilder::packageHoistedValue(const HoistedVal& hoisted,
137137 scratchIdx = *scratch;
138138 }
139139 for (Index i = 1 , size = type.size (); i < size; ++i) {
140- push (builder.makeTupleExtract (builder.makeLocalGet (scratchIdx, type), i));
140+ pushSynthetic (
141+ builder.makeTupleExtract (builder.makeLocalGet (scratchIdx, type), i));
141142 }
142143 return Ok{};
143144}
144145
145- void IRBuilder::push (Expression* expr) {
146+ void IRBuilder::push (Expression* expr, Origin origin ) {
146147 auto & scope = getScope ();
147148 if (expr->type == Type::unreachable) {
148149 scope.unreachable = true ;
149150 }
150151 scope.exprStack .push_back (expr);
151152
152- applyDebugLoc (expr);
153- if (binaryPos && func && lastBinaryPos != *binaryPos) {
154- auto span =
155- BinaryLocations::Span{BinaryLocation (lastBinaryPos - codeSectionOffset),
156- BinaryLocation (*binaryPos - codeSectionOffset)};
157- // Some expressions already have their start noted, and we are just seeing
158- // their last segment (like an Else).
159- auto [iter, inserted] = func->expressionLocations .insert ({expr, span});
160- if (!inserted) {
161- // Just update the end.
162- iter->second .end = span.end ;
163- // The true start from before is before the start of the current segment.
164- assert (iter->second .start < span.start );
153+ if (origin == Origin::Binary) {
154+ applyDebugLoc (expr);
155+ if (binaryPos && func && lastBinaryPos != *binaryPos) {
156+ auto span =
157+ BinaryLocations::Span{BinaryLocation (lastBinaryPos - codeSectionOffset),
158+ BinaryLocation (*binaryPos - codeSectionOffset)};
159+ // Some expressions already have their start noted, and we are just seeing
160+ // their last segment (like an Else).
161+ auto [iter, inserted] = func->expressionLocations .insert ({expr, span});
162+ if (!inserted) {
163+ // Just update the end.
164+ iter->second .end = span.end ;
165+ // The true start from before is before the start of the current
166+ // segment.
167+ assert (iter->second .start < span.start );
168+ }
169+ lastBinaryPos = *binaryPos;
165170 }
166- lastBinaryPos = *binaryPos;
167171 }
168172
169173 DBG (std::cerr << " After pushing " << ShallowExpression{expr} << " :\n " );
@@ -1018,7 +1022,7 @@ Result<> IRBuilder::visitCatch(Name tag) {
10181022 // Note that we have a pop to help determine later whether we need to run
10191023 // the fixup for pops within blocks.
10201024 scopeStack[0 ].notePop ();
1021- push (builder.makePop (params));
1025+ pushSynthetic (builder.makePop (params));
10221026 }
10231027
10241028 return Ok{};
0 commit comments