aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCohenArthur <arthur.cohen@epita.fr>2021-11-08 22:44:02 +0100
committerGitHub <noreply@github.com>2021-11-08 22:44:02 +0100
commit07fee63db7b06207917849410e12de750bdb646f (patch)
tree1bbb8b1cc483cd37180cc3197cc1780fc9824935
parentd11a50eca3773fb29430db6d3ea3ccc2bb4335fa (diff)
parenta7c31383def5c499864d61c5d00a1575d1cbff81 (diff)
downloadgcc-07fee63db7b06207917849410e12de750bdb646f.zip
gcc-07fee63db7b06207917849410e12de750bdb646f.tar.gz
gcc-07fee63db7b06207917849410e12de750bdb646f.tar.bz2
Merge pull request #792 from npate012/defid_to_struct
Change DefId type from uint64_t to be struct
-rw-r--r--gcc/rust/typecheck/rust-tyty.h8
-rw-r--r--gcc/rust/util/rust-hir-map.cc6
-rw-r--r--gcc/rust/util/rust-mapping-common.h25
3 files changed, 27 insertions, 12 deletions
diff --git a/gcc/rust/typecheck/rust-tyty.h b/gcc/rust/typecheck/rust-tyty.h
index ae9ff67..4472eee 100644
--- a/gcc/rust/typecheck/rust-tyty.h
+++ b/gcc/rust/typecheck/rust-tyty.h
@@ -1324,7 +1324,7 @@ public:
params (std::move (params)), type (type), flags (flags),
identifier (identifier), id (id), abi (abi)
{
- LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
@@ -1339,7 +1339,7 @@ public:
params (params), type (type), flags (flags), identifier (identifier),
id (id), abi (abi)
{
- LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
@@ -1519,7 +1519,7 @@ public:
parameter_types (std::move (parameter_types)),
result_type (std::move (result_type)), id (id)
{
- LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
@@ -1533,7 +1533,7 @@ public:
parameter_types (std::move (parameter_types)),
result_type (std::move (result_type)), id (id)
{
- LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ LocalDefId local_def_id = id.localDefId;
rust_assert (local_def_id != UNKNOWN_LOCAL_DEFID);
}
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index e965c23..9e5b509 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -63,7 +63,7 @@ NodeMapping::get_defid () const
DefId
NodeMapping::get_defid (CrateNum crate_num, LocalDefId local_defid)
{
- return ((uint64_t) crate_num << 32) | local_defid;
+ return DefId{crate_num, local_defid};
}
std::string
@@ -209,8 +209,8 @@ Mappings::insert_hir_crate (HIR::Crate *crate)
void
Mappings::insert_defid_mapping (DefId id, HIR::Item *item)
{
- CrateNum crate_num = (id & DEF_ID_CRATE_MASK) >> 32;
- LocalDefId local_def_id = id & DEF_ID_LOCAL_DEF_MASK;
+ CrateNum crate_num = id.crateNum;
+ LocalDefId local_def_id = id.localDefId;
rust_assert (lookup_defid (id) == nullptr);
rust_assert (lookup_local_defid (crate_num, local_def_id) == nullptr);
diff --git a/gcc/rust/util/rust-mapping-common.h b/gcc/rust/util/rust-mapping-common.h
index 1309a8d..0665779 100644
--- a/gcc/rust/util/rust-mapping-common.h
+++ b/gcc/rust/util/rust-mapping-common.h
@@ -31,17 +31,32 @@ typedef uint32_t NodeId;
typedef uint32_t HirId;
// refers to any top-level decl in HIR
typedef uint32_t LocalDefId;
-// refers to <Crate><DefId>
-typedef uint64_t DefId;
-#define DEF_ID_CRATE_MASK 0xFFFFFFFF00000000
-#define DEF_ID_LOCAL_DEF_MASK 0x00000000FFFFFFFF
+struct DefId
+{
+ CrateNum crateNum;
+ LocalDefId localDefId;
+
+ bool operator== (const DefId &other) const
+ {
+ return this->crateNum == other.crateNum
+ && this->localDefId == other.localDefId;
+ }
+
+ bool operator!= (const DefId &other) const { return !(*this == other); }
+
+ bool operator< (const DefId &other) const
+ {
+ return ((uint64_t) this->crateNum << 32 | this->localDefId)
+ < ((uint64_t) other.crateNum << 32 | other.localDefId);
+ }
+};
#define UNKNOWN_CREATENUM ((uint32_t) (0))
#define UNKNOWN_NODEID ((uint32_t) (0))
#define UNKNOWN_HIRID ((uint32_t) (0))
#define UNKNOWN_LOCAL_DEFID ((uint32_t) (0))
-#define UNKNOWN_DEFID ((uint64_t) (0))
+#define UNKNOWN_DEFID (DefId{0, 0})
} // namespace Rust