Skip to content

Commit

Permalink
Fix issue where getting the ident binding time only works for 4.08. (j…
Browse files Browse the repository at this point in the history
…aredly#363)

* Fix issue where getting the ident binding time only works for 4.08.

* Cosmetic: make the ident hack explicit so it's clear it only works for 408.
  • Loading branch information
cristianoc authored and jaredly committed Dec 12, 2019
1 parent fcac32a commit d833879
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 91 deletions.
6 changes: 3 additions & 3 deletions core/Query.re
Expand Up @@ -46,17 +46,17 @@ let findInScope = (pos, name, stamps) => {

let rec joinPaths = (modulePath, path) => {
switch modulePath {
| Path.Pident(ident) => (Current.ident_binding_time(ident), Ident.name(ident), path)
| Path.Pident(ident) => (Current.ident_binding_time_408(ident), Ident.name(ident), path)
| Path.Papply(fnPath, _argPath) => joinPaths(fnPath, path)
| Path.Pdot(inner, name) => joinPaths(inner, Nested(name, path))
}
};

let rec makePath = (modulePath) => {
switch modulePath {
| Path.Pident(ident) when Current.ident_binding_time(ident) === 0 =>
| Path.Pident(ident) when Current.ident_binding_time_408(ident) === 0 =>
`GlobalMod(Ident.name(ident))
| Path.Pident(ident) => `Stamp(Current.ident_binding_time(ident))
| Path.Pident(ident) => `Stamp(Current.ident_binding_time_408(ident))
| Path.Papply(fnPath, _argPath) => makePath(fnPath)
| Path.Pdot(inner, name) => `Path(joinPaths(inner, Tip(name)))
}
Expand Down
6 changes: 3 additions & 3 deletions ocaml_typing/current/Current.ml
Expand Up @@ -14,14 +14,14 @@ type longident = Longident.t =

type abstract_ident = Ident.t

type ident =
type ident_408 =
| Local of { name: string; stamp: int }
| Scoped of { name: string; stamp: int; scope: int }
| Global of string
| Predef of { name: string; stamp: int }

let ident_binding_time ident =
let current_ident = (Obj.magic ident : ident) in
let ident_binding_time_408 (ident: Ident.t) =
let current_ident = (Obj.magic ident : ident_408) in
match current_ident with
| Predef { stamp }
| Scoped { stamp }
Expand Down
28 changes: 14 additions & 14 deletions process_ocaml/402/ProcessCmt.re
Expand Up @@ -107,7 +107,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
let declared = addItem(
~name=Location.mknoloc(Ident.name(ident)),
~extent=loc,
~stamp=Current.ident_binding_time(ident),
~stamp=Ident.binding_time(ident),
~env,
~contents,
val_attributes,
Expand Down Expand Up @@ -139,7 +139,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
| Type_variant(constructors) => {
Variant(constructors |. Belt.List.map(({cd_loc, cd_id, cd_args, cd_res, cd_attributes}) => {
let name = Ident.name(cd_id);
let stamp = Current.ident_binding_time(cd_id);
let stamp = Ident.binding_time(cd_id);
let contents = {
Type.Constructor.stamp,
name: Location.mknoloc(name),
Expand Down Expand Up @@ -169,13 +169,13 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
}
| Type_record(labels, _) => Record(labels |> List.map(
({ld_id, ld_type}) => {
let astamp = Current.ident_binding_time(ld_id);
let astamp = Ident.binding_time(ld_id);
let name = Ident.name(ld_id);
{Type.Attribute.stamp: astamp, name: Location.mknoloc(name), typ: Shared.makeFlexible(ld_type), typLoc: Location.none}
}
))
}
}, ~name=Location.mknoloc(Ident.name(ident)), ~stamp=Current.ident_binding_time(ident), ~env, type_attributes, exported.types, env.stamps.types);
}, ~name=Location.mknoloc(Ident.name(ident)), ~stamp=Ident.binding_time(ident), ~env, type_attributes, exported.types, env.stamps.types);
[{...declared, contents: Module.Type(declared.contents)}]
}
/* | Sig_module({stamp, name}, {md_type: Mty_ident(path) | Mty_alias(path), md_attributes, md_loc}, _) =>
Expand All @@ -190,7 +190,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
~extent=md_loc,
~contents=forModuleType(env, md_type),
~name=Location.mknoloc(Ident.name(ident)),
~stamp=Current.ident_binding_time(ident),
~stamp=Ident.binding_time(ident),
~env,
md_attributes,
exported.modules,
Expand Down Expand Up @@ -227,7 +227,7 @@ let getModuleTypePath = (mod_desc) => switch mod_desc {
};

let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, typ_params, typ_name: name, typ_attributes, typ_type, typ_kind, typ_manifest}) => {
let stamp = Current.ident_binding_time(typ_id);
let stamp = Ident.binding_time(typ_id);
let declared = addItem(~extent=typ_loc, ~contents={
Type.params: typ_params |> List.map(((t, _)) => (Shared.makeFlexible(t.ctyp_type), t.ctyp_loc)),
typ: Shared.makeDeclaration(typ_type),
Expand All @@ -244,7 +244,7 @@ let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, ty
}
| Ttype_open => Open
| Ttype_variant(constructors) => Variant(constructors |> List.map(({cd_id, cd_name: name, cd_args, cd_res}) => {
let stamp = Current.ident_binding_time(cd_id);
let stamp = Ident.binding_time(cd_id);
{
Type.Constructor.stamp,
name,
Expand All @@ -254,7 +254,7 @@ let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, ty
}}))
| Ttype_record(labels) => Record(labels |> List.map(
({ld_id, ld_name: name, ld_type: {ctyp_type, ctyp_loc}}) => {
let astamp = Current.ident_binding_time(ld_id);
let astamp = Ident.binding_time(ld_id);
{Type.Attribute.stamp: astamp, name, typ: Shared.makeFlexible(ctyp_type), typLoc: ctyp_loc}
}))
}
Expand All @@ -267,7 +267,7 @@ let forSignatureItem = (~env, ~exported: Module.exported, item) => {
| Tsig_value({val_id, val_loc, val_name: name, val_desc, val_attributes}) => {
let declared = addItem(
~name,
~stamp=Current.ident_binding_time(val_id),
~stamp=Ident.binding_time(val_id),
~extent=val_loc,
~contents={Value.typ: Shared.makeFlexible(val_desc.ctyp_type), recursive: false},
~env,
Expand All @@ -282,7 +282,7 @@ let forSignatureItem = (~env, ~exported: Module.exported, item) => {
}
| Tsig_module({md_id, md_attributes, md_loc, md_name: name, md_type: {mty_type}}) => {
let contents = forModuleType(env, mty_type);
let declared = addItem(~contents, ~name, ~extent=md_loc, ~stamp=Current.ident_binding_time(md_id), ~env, md_attributes, exported.modules, env.stamps.modules);
let declared = addItem(~contents, ~name, ~extent=md_loc, ~stamp=Ident.binding_time(md_id), ~env, md_attributes, exported.modules, env.stamps.modules);
[{...declared, contents: Module.Module(declared.contents)}]
}
| Tsig_include({incl_mod, incl_type}) =>
Expand Down Expand Up @@ -342,14 +342,14 @@ let rec forItem = (
Value.recursive: false,
typ: Shared.makeFlexible(pat_type),
};
let declared = addItem(~name, ~stamp=Current.ident_binding_time(ident), ~env, ~extent=vb_loc, ~contents, vb_attributes, exported.values, env.stamps.values);
let declared = addItem(~name, ~stamp=Ident.binding_time(ident), ~env, ~extent=vb_loc, ~contents, vb_attributes, exported.values, env.stamps.values);
Some({...declared, contents: Module.Value(declared.contents)})
| _ => None
},
bindings)
| Tstr_module({mb_id, mb_attributes, mb_loc, mb_name: name, mb_expr: {mod_desc}}) => {
let contents = forModule(env, mod_desc, name.txt);
let declared = addItem(~contents, ~name, ~extent=mb_loc, ~stamp=Current.ident_binding_time(mb_id), ~env, mb_attributes, exported.modules, env.stamps.modules);
let declared = addItem(~contents, ~name, ~extent=mb_loc, ~stamp=Ident.binding_time(mb_id), ~env, mb_attributes, exported.modules, env.stamps.modules);
[{...declared, contents: Module.Module(declared.contents)}]
}
| Tstr_include({incl_mod, incl_type}) =>
Expand All @@ -367,7 +367,7 @@ let rec forItem = (
topLevel

| Tstr_primitive({val_id, val_name: name, val_loc, val_attributes, val_val: {val_type}}) => {
let declared = addItem(~extent=val_loc, ~contents={Value.recursive: false, typ: Shared.makeFlexible(val_type)}, ~name, ~stamp=Current.ident_binding_time(val_id), ~env, val_attributes, exported.values, env.stamps.values);
let declared = addItem(~extent=val_loc, ~contents={Value.recursive: false, typ: Shared.makeFlexible(val_type)}, ~name, ~stamp=Ident.binding_time(val_id), ~env, val_attributes, exported.values, env.stamps.values);
[{...declared, contents: Module.Value(declared.contents)}]
}
| Tstr_type(decls) =>
Expand All @@ -384,7 +384,7 @@ and forModule = (env, mod_desc, moduleName) => switch mod_desc {
}
| Tmod_functor(ident, argName, maybeType, resultExpr) => {
maybeType |?< t => forTreeModuleType(~env, t) |?< kind => {
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
let declared = newDeclared(
~contents=kind,
~name=argName,
Expand Down
6 changes: 3 additions & 3 deletions process_ocaml/402/ProcessExtra.re
Expand Up @@ -358,7 +358,7 @@ module F = (Collector: {

let enter_signature_item = item => switch (item.sig_desc) {
| Tsig_value({val_id, val_loc, val_name: name, val_desc, val_attributes}) => {
let stamp = Current.ident_binding_time(val_id);
let stamp = Ident.binding_time(val_id);
if (!Hashtbl.mem(Collector.file.stamps.values, stamp)) {
let declared = ProcessAttributes.newDeclared(
~name,
Expand Down Expand Up @@ -429,12 +429,12 @@ module F = (Collector: {
addForConstructor(pat_type, lident, constructor)
}
| Tpat_alias(_inner, ident, name) => {
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
addForPattern(stamp, name);
}
| Tpat_var(ident, name) => {
/* Log.log("Pattern " ++ name.txt); */
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
addForPattern(stamp, name);
}
| _ => ()
Expand Down
28 changes: 14 additions & 14 deletions process_ocaml/406/ProcessCmt.re
Expand Up @@ -107,7 +107,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
let declared = addItem(
~name=Location.mknoloc(Ident.name(ident)),
~extent=loc,
~stamp=Current.ident_binding_time(ident),
~stamp=Ident.binding_time(ident),
~env,
~contents,
val_attributes,
Expand Down Expand Up @@ -139,7 +139,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
| Type_variant(constructors) => {
Variant(constructors |. Belt.List.map(({cd_loc, cd_id, cd_args, cd_res, cd_attributes}) => {
let name = Ident.name(cd_id);
let stamp = Current.ident_binding_time(cd_id);
let stamp = Ident.binding_time(cd_id);
let contents = {
Type.Constructor.stamp,
name: Location.mknoloc(name),
Expand Down Expand Up @@ -173,13 +173,13 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
}
| Type_record(labels, _) => Record(labels |> List.map(
({ld_id, ld_type}) => {
let astamp = Current.ident_binding_time(ld_id);
let astamp = Ident.binding_time(ld_id);
let name = Ident.name(ld_id);
{Type.Attribute.stamp: astamp, name: Location.mknoloc(name), typ: Shared.makeFlexible(ld_type), typLoc: Location.none}
}
))
}
}, ~name=Location.mknoloc(Ident.name(ident)), ~stamp=Current.ident_binding_time(ident), ~env, type_attributes, exported.types, env.stamps.types);
}, ~name=Location.mknoloc(Ident.name(ident)), ~stamp=Ident.binding_time(ident), ~env, type_attributes, exported.types, env.stamps.types);
[{...declared, contents: Module.Type(declared.contents)}]
}
/* | Sig_module({stamp, name}, {md_type: Mty_ident(path) | Mty_alias(path), md_attributes, md_loc}, _) =>
Expand All @@ -194,7 +194,7 @@ let rec forSignatureTypeItem = (env, exported: SharedTypes.Module.exported, item
~extent=md_loc,
~contents=forModuleType(env, md_type),
~name=Location.mknoloc(Ident.name(ident)),
~stamp=Current.ident_binding_time(ident),
~stamp=Ident.binding_time(ident),
~env,
md_attributes,
exported.modules,
Expand Down Expand Up @@ -231,7 +231,7 @@ let getModuleTypePath = (mod_desc) => switch mod_desc {
};

let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, typ_params, typ_name: name, typ_attributes, typ_type, typ_kind, typ_manifest}) => {
let stamp = Current.ident_binding_time(typ_id);
let stamp = Ident.binding_time(typ_id);
let declared = addItem(~extent=typ_loc, ~contents={
Type.params: typ_params |> List.map(((t, _)) => (Shared.makeFlexible(t.ctyp_type), t.ctyp_loc)),
typ: Shared.makeDeclaration(typ_type),
Expand All @@ -248,7 +248,7 @@ let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, ty
}
| Ttype_open => Open
| Ttype_variant(constructors) => Variant(constructors |> List.map(({cd_id, cd_name: name, cd_args, cd_res}) => {
let stamp = Current.ident_binding_time(cd_id);
let stamp = Ident.binding_time(cd_id);
{
Type.Constructor.stamp,
name,
Expand All @@ -262,7 +262,7 @@ let forTypeDeclaration = (~env, ~exported: Module.exported, {typ_id, typ_loc, ty
}}))
| Ttype_record(labels) => Record(labels |> List.map(
({ld_id, ld_name: name, ld_type: {ctyp_type, ctyp_loc}}) => {
let astamp = Current.ident_binding_time(ld_id);
let astamp = Ident.binding_time(ld_id);
{Type.Attribute.stamp: astamp, name, typ: Shared.makeFlexible(ctyp_type), typLoc: ctyp_loc}
}))
}
Expand All @@ -275,7 +275,7 @@ let forSignatureItem = (~env, ~exported: Module.exported, item) => {
| Tsig_value({val_id, val_loc, val_name: name, val_desc, val_attributes}) => {
let declared = addItem(
~name,
~stamp=Current.ident_binding_time(val_id),
~stamp=Ident.binding_time(val_id),
~extent=val_loc,
~contents={Value.typ: Shared.makeFlexible(val_desc.ctyp_type), recursive: false},
~env,
Expand All @@ -290,7 +290,7 @@ let forSignatureItem = (~env, ~exported: Module.exported, item) => {
}
| Tsig_module({md_id, md_attributes, md_loc, md_name: name, md_type: {mty_type}}) => {
let contents = forModuleType(env, mty_type);
let declared = addItem(~contents, ~name, ~extent=md_loc, ~stamp=Current.ident_binding_time(md_id), ~env, md_attributes, exported.modules, env.stamps.modules);
let declared = addItem(~contents, ~name, ~extent=md_loc, ~stamp=Ident.binding_time(md_id), ~env, md_attributes, exported.modules, env.stamps.modules);
[{...declared, contents: Module.Module(declared.contents)}]
}
| Tsig_include({incl_mod, incl_type}) =>
Expand Down Expand Up @@ -350,14 +350,14 @@ let rec forItem = (
Value.recursive: false,
typ: Shared.makeFlexible(pat_type),
};
let declared = addItem(~name, ~stamp=Current.ident_binding_time(ident), ~env, ~extent=vb_loc, ~contents, vb_attributes, exported.values, env.stamps.values);
let declared = addItem(~name, ~stamp=Ident.binding_time(ident), ~env, ~extent=vb_loc, ~contents, vb_attributes, exported.values, env.stamps.values);
Some({...declared, contents: Module.Value(declared.contents)})
| _ => None
},
bindings)
| Tstr_module({mb_id, mb_attributes, mb_loc, mb_name: name, mb_expr: {mod_desc}}) => {
let contents = forModule(env, mod_desc, name.txt);
let declared = addItem(~contents, ~name, ~extent=mb_loc, ~stamp=Current.ident_binding_time(mb_id), ~env, mb_attributes, exported.modules, env.stamps.modules);
let declared = addItem(~contents, ~name, ~extent=mb_loc, ~stamp=Ident.binding_time(mb_id), ~env, mb_attributes, exported.modules, env.stamps.modules);
[{...declared, contents: Module.Module(declared.contents)}]
}
| Tstr_include({incl_mod, incl_type}) =>
Expand All @@ -375,7 +375,7 @@ let rec forItem = (
topLevel

| Tstr_primitive({val_id, val_name: name, val_loc, val_attributes, val_val: {val_type}}) => {
let declared = addItem(~extent=val_loc, ~contents={Value.recursive: false, typ: Shared.makeFlexible(val_type)}, ~name, ~stamp=Current.ident_binding_time(val_id), ~env, val_attributes, exported.values, env.stamps.values);
let declared = addItem(~extent=val_loc, ~contents={Value.recursive: false, typ: Shared.makeFlexible(val_type)}, ~name, ~stamp=Ident.binding_time(val_id), ~env, val_attributes, exported.values, env.stamps.values);
[{...declared, contents: Module.Value(declared.contents)}]
}
| Tstr_type(_, decls) =>
Expand All @@ -392,7 +392,7 @@ and forModule = (env, mod_desc, moduleName) => switch mod_desc {
}
| Tmod_functor(ident, argName, maybeType, resultExpr) => {
maybeType |?< t => forTreeModuleType(~env, t) |?< kind => {
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
let declared = newDeclared(
~contents=kind,
~name=argName,
Expand Down
6 changes: 3 additions & 3 deletions process_ocaml/406/ProcessExtra.re
Expand Up @@ -358,7 +358,7 @@ module F = (Collector: {

let enter_signature_item = item => switch (item.sig_desc) {
| Tsig_value({val_id, val_loc, val_name: name, val_desc, val_attributes}) => {
let stamp = Current.ident_binding_time(val_id);
let stamp = Ident.binding_time(val_id);
if (!Hashtbl.mem(Collector.file.stamps.values, stamp)) {
let declared = ProcessAttributes.newDeclared(
~name,
Expand Down Expand Up @@ -429,12 +429,12 @@ module F = (Collector: {
addForConstructor(pat_type, lident, constructor)
}
| Tpat_alias(_inner, ident, name) => {
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
addForPattern(stamp, name);
}
| Tpat_var(ident, name) => {
/* Log.log("Pattern " ++ name.txt); */
let stamp = Current.ident_binding_time(ident);
let stamp = Ident.binding_time(ident);
addForPattern(stamp, name);
}
| _ => ()
Expand Down

0 comments on commit d833879

Please sign in to comment.