Skip to content

Commit

Permalink
Disassociate obligations from method calls.
Browse files Browse the repository at this point in the history
Rustc updates caused more obligations to associate with method call
exprs. This means that no call tables will be built for now but we can
re-establish the functionality once we figure out where the difference
is coming from.

Frontend updates simplify the communication process which should cut
down on syncing issues.
  • Loading branch information
gavinleroy committed May 23, 2024
1 parent 4bf06a5 commit 605828a
Show file tree
Hide file tree
Showing 15 changed files with 232 additions and 131 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ If rustup fails, especially with an error like "could not rename the downloaded
To solve the issue, go to the command line and run:

```
rustup toolchain install nightly-2024-04-08 -c rust-src -c rustc-dev -c llvm-tools-preview
rustup toolchain install nightly-2024-05-20 -c rust-src -c rustc-dev -c llvm-tools-preview
```

Then go back to VSCode and click "Continue" to let Argus continue installing.
Expand Down
18 changes: 15 additions & 3 deletions crates/argus/src/analysis/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl BinCreator<'_, '_> {
.collect::<Vec<_>>();

if !obligations.is_empty() {
log::debug!(
"Associating obligations with {kind:?} {:?}\n{:#?}",
self.ctx.tcx.hir().node_to_string(target),
obligations
);

self.bins.push(Bin {
hir_id: target,
obligations,
Expand All @@ -104,23 +110,29 @@ impl BinCreator<'_, '_> {
}

impl<'a, 'tcx: 'a> HirVisitor<'_> for BinCreator<'a, 'tcx> {
// FIXME: after updating to nightly-2024-05-20 this binning logic broke slightly.
// Obligations associated with parameters are now being assigned to the overall call,
// this makes more things use a method call table than necessary.
fn visit_expr(&mut self, ex: &hir::Expr) {
// Drain nested obligations first to match the most specific node possible.
hir::intravisit::walk_expr(self, ex);

match ex.kind {
hir::ExprKind::Call(callable, args) => {
self.drain_nested(callable.hir_id, BinKind::CallableExpr);
for arg in args {
self.drain_nested(arg.hir_id, BinKind::CallArg);
}
self.drain_nested(callable.hir_id, BinKind::CallableExpr);
self.drain_nested(ex.hir_id, BinKind::Call);
}
hir::ExprKind::MethodCall(_, func, args, _) => {
self.drain_nested(func.hir_id, BinKind::MethodReceiver);
for arg in args {
self.drain_nested(arg.hir_id, BinKind::CallArg);
}
self.drain_nested(ex.hir_id, BinKind::MethodCall);
self.drain_nested(func.hir_id, BinKind::MethodReceiver);
// [ ] TODO (see above `FIXME`):
// self.drain_nested(ex.hir_id, BinKind::MethodCall);
self.drain_nested(ex.hir_id, BinKind::Misc);
}
_ => {}
}
Expand Down
6 changes: 2 additions & 4 deletions crates/argus/src/serialize/path/default.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Default implementaitons from rustc_middle::ty::print
use log::debug;
use rustc_data_structures::sso::SsoHashSet;
use rustc_hir::{def_id::DefId, definitions::DefPathData};
use rustc_middle::ty::{self, *};
Expand Down Expand Up @@ -38,7 +37,7 @@ impl<'a, 'tcx: 'a> PathBuilderDefault<'tcx> for PathBuilder<'a, 'tcx> {
args: &'tcx [GenericArg<'tcx>],
) {
let key = self.tcx().def_key(def_id);
debug!("{:?}", key);
log::trace!("default_print_def_path {:?}", key);

match key.disambiguated_data.data {
DefPathData::CrateRoot => {
Expand Down Expand Up @@ -124,7 +123,6 @@ impl<'a, 'tcx: 'a> PathBuilderDefault<'tcx> for PathBuilder<'a, 'tcx> {
)
}
};
debug!("Returning from default_print_def_path");
}

fn print_impl_path(
Expand All @@ -144,7 +142,7 @@ impl<'a, 'tcx: 'a> PathBuilderDefault<'tcx> for PathBuilder<'a, 'tcx> {
self_ty: Ty<'tcx>,
impl_trait_ref: Option<ty::TraitRef<'tcx>>,
) {
debug!(
log::trace!(
"default_print_impl_path: impl_def_id={:?}, self_ty={}, impl_trait_ref={:?}",
impl_def_id, self_ty, impl_trait_ref
);
Expand Down
2 changes: 1 addition & 1 deletion crates/argus/src/serialize/path/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl<'a, 'tcx: 'a> PathBuilder<'a, 'tcx> {
) {
print_prefix(self);

log::debug!("pretty_path_append_impl {:?} {:?}", self_ty, trait_ref);
log::trace!("pretty_path_append_impl {:?} {:?}", self_ty, trait_ref);

self.generic_delimiters(|cx| {
// CHANGE: define_scoped_cx!(cx);
Expand Down
4 changes: 3 additions & 1 deletion crates/argus/src/serialize/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ pub enum AliasTyKindDef<'tcx> {
impl<'tcx> AliasTyKindDef<'tcx> {
pub fn new(kind: ty::AliasTyKind, ty: ty::AliasTy<'tcx>) -> Self {
let infcx = get_dynamic_ctx();
log::debug!("Serializing type Alias {:?} {:?}", kind, ty);

match (kind, ty) {
(
ty::AliasTyKind::Projection
Expand Down Expand Up @@ -1907,7 +1909,7 @@ impl<'tcx> OpaqueImpl<'tcx> {
// by looking up the projections associated with the def_id.
let bounds = tcx.explicit_item_bounds(def_id);

log::debug!("Explicit item bounds {:?}", bounds);
log::trace!("Explicit item bounds {:?}", bounds);

let mut traits = FxIndexMap::default();
let mut fn_traits = FxIndexMap::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ async fn handler() {
async fn test() {
crate::use_as_handler!(handler);
}

35 changes: 17 additions & 18 deletions ide/packages/common/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,20 @@ export const ConfigConsts = {
// ----------------------------------------------------
// Panoptes initial configuration for a single webview

export type PanoptesInitialData = {
data: [Filename, ObligationsInBody[]][];
export type PanoptesOptionalData = {
target?: ErrorJumpTargetInfo;
evalMode?: EvaluationMode;
};

export type SystemSpec = Omit<IssueOptions, "logText">;
export type EvaluationMode = "release" | "rank" | "random";

export type PanoptesConfig = PanoptesInitialData &
export type PanoptesConfig = PanoptesOptionalData &
(
| {
type: "VSCODE_BACKING";
spec: SystemSpec;
data: [Filename, ObligationsInBody[]][];
}
| {
type: "WEB_BUNDLE";
Expand Down Expand Up @@ -92,28 +92,25 @@ export type PayloadTypes = {
};

export type SystemToPanoptesCmds =
| "reset"
| "havoc"
| "open-file"
| "open-error"
| "obligations"
| "tree";

export type SystemToPanoptesMsg<T extends SystemToPanoptesCmds> = {
command: T;
type: FROM_EXT;
} & (T extends "reset"
? { data: [Filename, ObligationsInBody[]][] }
} & (T extends "havoc"
? {}
: CommonData &
(T extends "open-file"
? { data: ObligationsInBody[] }
? { data: ObligationsInBody[]; signature: string }
: T extends "open-error"
? {
bodyIdx: BodyHash;
exprIdx: ExprIdx;
hash: ObligationHash;
}
: T extends "obligations"
? { obligations: ObligationsInBody[] }
: T extends "tree"
? { tree?: SerializedTree }
: never));
Expand Down Expand Up @@ -196,24 +193,26 @@ export function isSysMsgOpenFile(
return objWCmd(msg) && msg.command === "open-file";
}

export function isSysMsgReset(
export function isSysMsgHavoc(
msg: unknown
): msg is SystemToPanoptesMsg<"reset"> {
return objWCmd(msg) && msg.command === "reset";
): msg is SystemToPanoptesMsg<"havoc"> {
return objWCmd(msg) && msg.command === "havoc";
}

export function isPanoMsgTree(
msg: unknown
): msg is PanoptesToSystemMsg<"tree"> {
return objWCmd(msg) && msg.command === "tree";
}
// ------------------------------------------------------

export function isPanoMsgObligations(
msg: unknown
): msg is PanoptesToSystemMsg<"obligations"> {
return objWCmd(msg) && msg.command === "obligations";
}

export function isPanoMsgTree(
msg: unknown
): msg is PanoptesToSystemMsg<"tree"> {
return objWCmd(msg) && msg.command === "tree";
}

export function isPanoMsgAddHighlight(
msg: unknown
): msg is PanoptesToSystemMsg<"add-highlight"> {
Expand Down
1 change: 0 additions & 1 deletion ide/packages/evaluation/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ export function webHtml(
const config: PanoptesConfig = {
type: "WEB_BUNDLE",
target: findErrorTargetInBundles(bundles),
data: [[filename, bundles.map(b => b.body)]],
closedSystem: bundles,
evalMode,
};
Expand Down
Loading

0 comments on commit 605828a

Please sign in to comment.