Skip to content

Commit 5a3c340

Browse files
authored
Merge pull request #117 from ucb-substrate/compiler_debug_info
feat(compiler): add span to inconsistent constraints
2 parents 934e846 + be3b83f commit 5a3c340

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ vim.cmd([[autocmd BufRead,BufNewFile *.ar setfiletype argon]])
5858
To open an example Argon workspace, run the following from the root directory of your Argon clone:
5959

6060
```
61-
vim pdks/sky130/lib.ar
61+
nvim pdks/sky130/lib.ar
6262
```
6363

6464
Start the GUI by running `:Argon gui`.

core/compiler/src/compile.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,6 +1873,7 @@ struct ExecScope {
18731873
struct FallbackConstraint {
18741874
priority: i32,
18751875
constraint: LinearExpr,
1876+
span: Span,
18761877
}
18771878

18781879
impl PartialEq for FallbackConstraint {
@@ -1908,6 +1909,7 @@ struct CellState {
19081909
fallback_constraints: BinaryHeap<FallbackConstraint>,
19091910
fallback_constraints_used: Vec<LinearExpr>,
19101911
unsolved_vars: Option<IndexSet<Var>>,
1912+
constraint_span_map: IndexMap<ConstraintId, Span>,
19111913
}
19121914

19131915
struct ExecPass<'a> {
@@ -2138,6 +2140,7 @@ impl<'a> ExecPass<'a> {
21382140
root_scope: root_scope_id,
21392141
unsolved_vars: Default::default(),
21402142
objects: Default::default(),
2143+
constraint_span_map: IndexMap::new(),
21412144
}
21422145
)
21432146
.is_none()
@@ -2218,16 +2221,18 @@ impl<'a> ExecPass<'a> {
22182221
}
22192222
let mut constraint_added = false;
22202223
let state = self.cell_state_mut(cell_id);
2221-
while let Some(FallbackConstraint { constraint, .. }) =
2222-
state.fallback_constraints.pop()
2224+
while let Some(FallbackConstraint {
2225+
constraint, span, ..
2226+
}) = state.fallback_constraints.pop()
22232227
{
22242228
if constraint
22252229
.coeffs
22262230
.iter()
22272231
.any(|(c, v)| c.abs() > 1e-6 && !state.solver.is_solved(*v))
22282232
{
22292233
state.fallback_constraints_used.push(constraint.clone());
2230-
state.solver.constrain_eq0(constraint);
2234+
let constraint_id = state.solver.constrain_eq0(constraint);
2235+
state.constraint_span_map.insert(constraint_id, span);
22312236
constraint_added = true;
22322237
break;
22332238
}
@@ -2246,18 +2251,25 @@ impl<'a> ExecPass<'a> {
22462251
require_progress = true;
22472252
}
22482253
}
2254+
22492255
let state = self.cell_state_mut(cell_id);
22502256
if progress {
22512257
state.solve_iters += 1;
22522258
state.solver.solve();
22532259
}
22542260
for constraint in state.solver.inconsistent_constraints().clone() {
2261+
let span = self
2262+
.cell_state(cell_id)
2263+
.constraint_span_map
2264+
.get(&constraint)
2265+
.cloned();
22552266
self.errors.push(ExecError {
2256-
span: None,
2267+
span,
22572268
cell: cell_id,
22582269
kind: ExecErrorKind::InconsistentConstraint(constraint),
22592270
});
22602271
}
2272+
22612273
self.partial_cells
22622274
.pop_back()
22632275
.expect("failed to pop cell id");
@@ -2897,6 +2909,7 @@ impl<'a> ExecPass<'a> {
28972909
}
28982910
x => unreachable!("unsupported kwarg `{x}`"),
28992911
};
2912+
let span = self.span(&vref.loc, kwarg.span);
29002913
let defer = self.value_id();
29012914
self.values.insert(
29022915
defer,
@@ -2906,6 +2919,7 @@ impl<'a> ExecPass<'a> {
29062919
rhs: *rhs,
29072920
fallback: kwarg.name.name.ends_with('i'),
29082921
priority,
2922+
span,
29092923
}),
29102924
loc: vref.loc,
29112925
}),
@@ -3038,7 +3052,15 @@ impl<'a> ExecPass<'a> {
30383052
) {
30393053
let expr = vl.as_ref().unwrap_linear().clone()
30403054
- vr.as_ref().unwrap_linear().clone();
3041-
state.solver.constrain_eq0(expr);
3055+
let constraint = state.solver.constrain_eq0(expr);
3056+
3057+
state.constraint_span_map.insert(
3058+
constraint,
3059+
Span {
3060+
path: state.scopes[&vref.loc.scope].span.path.clone(),
3061+
span: c.expr.span,
3062+
},
3063+
);
30423064
self.values.insert(vid, Defer::Ready(Value::Nil));
30433065
true
30443066
} else {
@@ -3123,6 +3145,7 @@ impl<'a> ExecPass<'a> {
31233145
constraint,
31243146
span: Some(span.clone()),
31253147
};
3148+
state.constraint_span_map.insert(constraint, span.clone());
31263149
state.object_emit.push(ObjectEmit {
31273150
scope: vref.loc.scope,
31283151
object: dim.id,
@@ -3253,6 +3276,7 @@ impl<'a> ExecPass<'a> {
32533276
}
32543277
_ => continue,
32553278
};
3279+
let span = self.span(&vref.loc, kwarg.span);
32563280
let defer = self.value_id();
32573281
self.values.insert(
32583282
defer,
@@ -3262,6 +3286,7 @@ impl<'a> ExecPass<'a> {
32623286
rhs: *rhs,
32633287
fallback: kwarg.name.name.ends_with('i'),
32643288
priority,
3289+
span,
32653290
}),
32663291
loc: vref.loc,
32673292
}),
@@ -3693,9 +3718,11 @@ impl<'a> ExecPass<'a> {
36933718
state.fallback_constraints.push(FallbackConstraint {
36943719
priority: c.priority,
36953720
constraint: expr,
3721+
span: c.span.clone(),
36963722
});
36973723
} else {
3698-
state.solver.constrain_eq0(expr);
3724+
let constraint = state.solver.constrain_eq0(expr);
3725+
state.constraint_span_map.insert(constraint, c.span.clone());
36993726
}
37003727
self.values.insert(vid, DeferValue::Ready(Value::Nil));
37013728
true
@@ -4268,6 +4295,7 @@ struct PartialConstraint {
42684295
rhs: ValueId,
42694296
fallback: bool,
42704297
priority: i32,
4298+
span: Span,
42714299
}
42724300

42734301
#[derive(Debug, Clone)]

core/lang-server/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl StateMut {
134134
.unwrap_or_else(|| {
135135
PathBuf::from(concat!(
136136
env!("CARGO_MANIFEST_DIR"),
137-
"/../../core/compiler/examples/lyp/basic.lyp"
137+
"/../../pdks/sky130/sky130.lyp"
138138
))
139139
});
140140
let parse_output = parse::parse_workspace_with_std(root_dir.join("lib.ar"));

0 commit comments

Comments
 (0)