2020-01-12 22:59:16 -05:00
|
|
|
// Graph abstraction
|
|
|
|
//
|
2021-07-22 15:00:15 -04:00
|
|
|
// Copyright (C) 2014-2021 Ryan Specialty Group, LLC.
|
2020-03-06 11:05:18 -05:00
|
|
|
//
|
|
|
|
// This file is part of TAME.
|
2020-01-12 22:59:16 -05:00
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
//! Abstract graph as the basis for concrete ASGs.
|
|
|
|
|
|
|
|
use super::ident::IdentKind;
|
2021-10-12 09:42:09 -04:00
|
|
|
use super::object::{FragmentText, IdentObjectState, Source, TransitionError};
|
2021-09-23 14:52:53 -04:00
|
|
|
use crate::sym::SymbolId;
|
2020-04-09 11:34:30 -04:00
|
|
|
use petgraph::graph::NodeIndex;
|
2020-03-19 10:10:12 -04:00
|
|
|
use std::fmt::Debug;
|
2020-01-12 22:59:16 -05:00
|
|
|
use std::result::Result;
|
|
|
|
|
2020-04-09 11:34:30 -04:00
|
|
|
/// Datatype representing node and edge indexes.
|
|
|
|
pub trait IndexType: petgraph::graph::IndexType {}
|
|
|
|
impl<T: petgraph::graph::IndexType> IndexType for T {}
|
|
|
|
|
2020-03-14 00:10:03 -04:00
|
|
|
/// An abstract semantic graph of [objects][super::object].
|
2020-01-12 22:59:16 -05:00
|
|
|
///
|
|
|
|
/// This IR focuses on the definition and manipulation of objects and their
|
|
|
|
/// dependencies.
|
2020-03-16 11:49:41 -04:00
|
|
|
/// See [`IdentObject`](super::object::IdentObject) for a summary of valid
|
|
|
|
/// identifier object state transitions.
|
2020-01-12 22:59:16 -05:00
|
|
|
///
|
|
|
|
/// Objects are never deleted from the graph,
|
|
|
|
/// so [`ObjectRef`]s will remain valid for the lifetime of the ASG.
|
|
|
|
///
|
|
|
|
/// For more information,
|
|
|
|
/// see the [module-level documentation][self].
|
2022-01-14 10:21:49 -05:00
|
|
|
pub trait Asg<O>
|
2020-03-14 00:10:03 -04:00
|
|
|
where
|
2021-09-23 14:52:53 -04:00
|
|
|
O: IdentObjectState<O>,
|
2020-03-14 00:10:03 -04:00
|
|
|
{
|
2020-01-12 22:59:16 -05:00
|
|
|
/// Declare a concrete identifier.
|
|
|
|
///
|
|
|
|
/// An identifier declaration is similar to a declaration in a header
|
|
|
|
/// file in a language like C,
|
|
|
|
/// describing the structure of the identifier.
|
|
|
|
/// Once declared,
|
|
|
|
/// this information cannot be changed.
|
|
|
|
///
|
tamer: Global interners
This is a major change, and I apologize for it all being in one commit. I
had wanted to break it up, but doing so would have required a significant
amount of temporary work that was not worth doing while I'm the only one
working on this project at the moment.
This accomplishes a number of important things, now that I'm preparing to
write the first compiler frontend for TAMER:
1. `Symbol` has been removed; `SymbolId` is used in its place.
2. Consequently, symbols use 16 or 32 bits, rather than a 64-bit pointer.
3. Using symbols no longer requires dereferencing.
4. **Lifetimes no longer pollute the entire system! (`'i`)**
5. Two global interners are offered to produce `SymbolStr` with `'static`
lifetimes, simplfiying lifetime management and borrowing where strings
are still needed.
6. A nice API is provided for interning and lookups (e.g. "foo".intern())
which makes this look like a core feature of Rust.
Unfortunately, making this change required modifications to...virtually
everything. And that serves to emphasize why this change was needed:
_everything_ used symbols, and so there's no use in not providing globals.
I implemented this in a way that still provides for loose coupling through
Rust's trait system. Indeed, Rustc offers a global interner, and I decided
not to go that route initially because it wasn't clear to me that such a
thing was desirable. It didn't become apparent to me, in fact, until the
recent commit where I introduced `SymbolIndexSize` and saw how many things
had to be touched; the linker evolved so rapidly as I was trying to learn
Rust that I lost track of how bad it got.
Further, this shows how the design of the internment system was a bit
naive---I assumed certain requirements that never panned out. In
particular, everything using symbols stored `&'i Symbol<'i>`---that is, a
reference (usize) to an object containing an index (32-bit) and a string
slice (128-bit). So it was a reference to a pretty large value, which was
allocated in the arena alongside the interned string itself.
But, that was assuming that something would need both the symbol index _and_
a readily available string. That's not the case. In fact, it's pretty
clear that interning happens at the beginning of execution, that `SymbolId`
is all that's needed during processing (unless an error occurs; more on that
below); and it's not until _the very end_ that we need to retrieve interned
strings from the pool to write either to a file or to display to the
user. It was horribly wasteful!
So `SymbolId` solves the lifetime issue in itself for most systems, but it
still requires that an interner be available for anything that needs to
create or resolve symbols, which, as it turns out, is still a lot of
things. Therefore, I decided to implement them as thread-local static
variables, which is very similar to what Rustc does itself (Rustc's are
scoped). TAMER does not use threads, so the resulting `'static` lifetime
should be just fine for now. Eventually I'd like to implement `!Send` and
`!Sync`, though, to prevent references from escaping the thread (as noted in
the patch); I can't do that yet, since the feature has not yet been
stabalized.
In the end, this leaves us with a system that's much easier to use and
maintain; hopefully easier for newcomers to get into without having to deal
with so many complex lifetimes; and a nice API that makes it a pleasure to
work with symbols.
Admittedly, the `SymbolIndexSize` adds some complexity, and we'll see if I
end up regretting that down the line, but it exists for an important reason:
the `Span` and other structures that'll be introduced need to pack a lot of
data into 64 bits so they can be freely copied around to keep lifetimes
simple without wreaking havoc in other ways, but a 32-bit symbol size needed
by the linker is too large for that. (Actually, the linker doesn't yet need
32 bits for our systems, but it's going to in the somewhat near future
unless we optimize away a bunch of symbols...but I'd really rather not have
the linker hit a limit that requires a lot of code changes to resolve).
Rustc uses interned spans when they exceed 8 bytes, but I'd prefer to avoid
that for now. Most systems can just use on of the `PkgSymbolId` or
`ProgSymbolId` type aliases and not have to worry about it. Systems that
are actually shared between the compiler and the linker do, though, but it's
not like we don't already have a bunch of trait bounds.
Of course, as we implement link-time optimizations (LTO) in the future, it's
possible most things will need the size and I'll grow frustrated with that
and possibly revisit this. We shall see.
Anyway, this was exhausting...and...onward to the first frontend!
2021-08-02 23:54:37 -04:00
|
|
|
/// Identifiers are uniquely identified by a [`SymbolId`] `name`.
|
2020-01-12 22:59:16 -05:00
|
|
|
/// If an identifier of the same `name` already exists,
|
|
|
|
/// then the provided declaration is compared against the existing
|
|
|
|
/// declaration---should
|
|
|
|
/// they be incompatible,
|
|
|
|
/// then the operation will fail;
|
|
|
|
/// otherwise,
|
|
|
|
/// the existing identifier will be returned.
|
2020-01-15 11:24:56 -05:00
|
|
|
///
|
2020-01-12 22:59:16 -05:00
|
|
|
/// If a concrete identifier has already been declared (see
|
|
|
|
/// [`Asg::declare`]),
|
2020-03-25 15:37:55 -04:00
|
|
|
/// then extern declarations will be compared and,
|
2020-01-12 22:59:16 -05:00
|
|
|
/// if compatible,
|
|
|
|
/// the identifier will be immediately _resolved_ and the object
|
|
|
|
/// on the graph will not be altered.
|
|
|
|
/// Resolution will otherwise fail in error.
|
2020-03-14 00:10:03 -04:00
|
|
|
///
|
2020-03-25 15:37:55 -04:00
|
|
|
/// For more information on state transitions that can occur when
|
|
|
|
/// redeclaring an identifier that already exists,
|
2020-03-26 00:43:04 -04:00
|
|
|
/// see [`IdentObjectState::resolve`].
|
2020-03-25 15:37:55 -04:00
|
|
|
///
|
|
|
|
/// A successful declaration will add an identifier to the graph
|
|
|
|
/// and return an [`ObjectRef`] reference.
|
|
|
|
fn declare(
|
2020-01-12 22:59:16 -05:00
|
|
|
&mut self,
|
2021-09-23 14:52:53 -04:00
|
|
|
name: SymbolId,
|
2020-03-25 15:37:55 -04:00
|
|
|
kind: IdentKind,
|
2021-09-23 14:52:53 -04:00
|
|
|
src: Source,
|
2022-01-14 10:21:49 -05:00
|
|
|
) -> AsgResult<ObjectRef>;
|
2020-01-12 22:59:16 -05:00
|
|
|
|
2020-03-25 15:37:55 -04:00
|
|
|
/// Declare an abstract identifier.
|
2020-03-25 23:49:37 -04:00
|
|
|
///
|
|
|
|
/// An _extern_ declaration declares an identifier the same as
|
|
|
|
/// [`Asg::declare`],
|
|
|
|
/// but omits source information.
|
|
|
|
/// Externs are identifiers that are expected to be defined somewhere
|
|
|
|
/// else ("externally"),
|
|
|
|
/// and are resolved at [link-time][crate::ld].
|
|
|
|
///
|
|
|
|
/// If a concrete identifier has already been declared (see
|
|
|
|
/// [`Asg::declare`]),
|
|
|
|
/// then the declarations will be compared and,
|
|
|
|
/// if compatible,
|
|
|
|
/// the identifier will be immediately _resolved_ and the object
|
|
|
|
/// on the graph will not be altered.
|
|
|
|
/// Resolution will otherwise fail in error.
|
|
|
|
///
|
|
|
|
/// See [`IdentObjectState::extern_`] and
|
2020-03-26 00:43:04 -04:00
|
|
|
/// [`IdentObjectState::resolve`] for more information on
|
2020-03-25 23:49:37 -04:00
|
|
|
/// compatibility related to extern resolution.
|
|
|
|
fn declare_extern(
|
|
|
|
&mut self,
|
2021-09-23 14:52:53 -04:00
|
|
|
name: SymbolId,
|
2020-03-25 23:49:37 -04:00
|
|
|
kind: IdentKind,
|
2021-09-23 14:52:53 -04:00
|
|
|
src: Source,
|
2022-01-14 10:21:49 -05:00
|
|
|
) -> AsgResult<ObjectRef>;
|
2020-03-25 15:37:55 -04:00
|
|
|
|
2020-01-12 22:59:16 -05:00
|
|
|
/// Set the fragment associated with a concrete identifier.
|
|
|
|
///
|
2020-03-14 00:10:03 -04:00
|
|
|
/// Fragments are intended for use by the [linker][crate::ld].
|
|
|
|
/// For more information,
|
2020-03-16 11:49:41 -04:00
|
|
|
/// see [`IdentObjectState::set_fragment`].
|
2020-01-12 22:59:16 -05:00
|
|
|
fn set_fragment(
|
|
|
|
&mut self,
|
2022-01-14 10:21:49 -05:00
|
|
|
identi: ObjectRef,
|
2021-09-23 14:52:53 -04:00
|
|
|
text: FragmentText,
|
2022-01-14 10:21:49 -05:00
|
|
|
) -> AsgResult<ObjectRef>;
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// Retrieve an object from the graph by [`ObjectRef`].
|
|
|
|
///
|
|
|
|
/// Since an [`ObjectRef`] should only be produced by an [`Asg`],
|
|
|
|
/// and since objects are never deleted from the graph,
|
|
|
|
/// this should never fail so long as references are not shared
|
|
|
|
/// between multiple graphs.
|
|
|
|
/// It is nevertheless wrapped in an [`Option`] just in case.
|
2022-01-14 10:21:49 -05:00
|
|
|
fn get<I: Into<ObjectRef>>(&self, index: I) -> Option<&O>;
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// Attempt to retrieve an identifier from the graph by name.
|
|
|
|
///
|
|
|
|
/// Since only identifiers carry a name,
|
|
|
|
/// this method cannot be used to retrieve all possible objects on the
|
|
|
|
/// graph---for
|
|
|
|
/// that, see [`Asg::get`].
|
2022-01-14 10:21:49 -05:00
|
|
|
fn lookup(&self, name: SymbolId) -> Option<ObjectRef>;
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// Declare that `dep` is a dependency of `ident`.
|
|
|
|
///
|
|
|
|
/// An object must be declared as a dependency if its value must be
|
|
|
|
/// computed before computing the value of `ident`.
|
|
|
|
/// The [linker][crate::ld] will ensure this ordering.
|
2020-01-14 16:26:36 -05:00
|
|
|
///
|
|
|
|
/// See [`add_dep_lookup`][Asg::add_dep_lookup] if identifiers have to
|
tamer: Global interners
This is a major change, and I apologize for it all being in one commit. I
had wanted to break it up, but doing so would have required a significant
amount of temporary work that was not worth doing while I'm the only one
working on this project at the moment.
This accomplishes a number of important things, now that I'm preparing to
write the first compiler frontend for TAMER:
1. `Symbol` has been removed; `SymbolId` is used in its place.
2. Consequently, symbols use 16 or 32 bits, rather than a 64-bit pointer.
3. Using symbols no longer requires dereferencing.
4. **Lifetimes no longer pollute the entire system! (`'i`)**
5. Two global interners are offered to produce `SymbolStr` with `'static`
lifetimes, simplfiying lifetime management and borrowing where strings
are still needed.
6. A nice API is provided for interning and lookups (e.g. "foo".intern())
which makes this look like a core feature of Rust.
Unfortunately, making this change required modifications to...virtually
everything. And that serves to emphasize why this change was needed:
_everything_ used symbols, and so there's no use in not providing globals.
I implemented this in a way that still provides for loose coupling through
Rust's trait system. Indeed, Rustc offers a global interner, and I decided
not to go that route initially because it wasn't clear to me that such a
thing was desirable. It didn't become apparent to me, in fact, until the
recent commit where I introduced `SymbolIndexSize` and saw how many things
had to be touched; the linker evolved so rapidly as I was trying to learn
Rust that I lost track of how bad it got.
Further, this shows how the design of the internment system was a bit
naive---I assumed certain requirements that never panned out. In
particular, everything using symbols stored `&'i Symbol<'i>`---that is, a
reference (usize) to an object containing an index (32-bit) and a string
slice (128-bit). So it was a reference to a pretty large value, which was
allocated in the arena alongside the interned string itself.
But, that was assuming that something would need both the symbol index _and_
a readily available string. That's not the case. In fact, it's pretty
clear that interning happens at the beginning of execution, that `SymbolId`
is all that's needed during processing (unless an error occurs; more on that
below); and it's not until _the very end_ that we need to retrieve interned
strings from the pool to write either to a file or to display to the
user. It was horribly wasteful!
So `SymbolId` solves the lifetime issue in itself for most systems, but it
still requires that an interner be available for anything that needs to
create or resolve symbols, which, as it turns out, is still a lot of
things. Therefore, I decided to implement them as thread-local static
variables, which is very similar to what Rustc does itself (Rustc's are
scoped). TAMER does not use threads, so the resulting `'static` lifetime
should be just fine for now. Eventually I'd like to implement `!Send` and
`!Sync`, though, to prevent references from escaping the thread (as noted in
the patch); I can't do that yet, since the feature has not yet been
stabalized.
In the end, this leaves us with a system that's much easier to use and
maintain; hopefully easier for newcomers to get into without having to deal
with so many complex lifetimes; and a nice API that makes it a pleasure to
work with symbols.
Admittedly, the `SymbolIndexSize` adds some complexity, and we'll see if I
end up regretting that down the line, but it exists for an important reason:
the `Span` and other structures that'll be introduced need to pack a lot of
data into 64 bits so they can be freely copied around to keep lifetimes
simple without wreaking havoc in other ways, but a 32-bit symbol size needed
by the linker is too large for that. (Actually, the linker doesn't yet need
32 bits for our systems, but it's going to in the somewhat near future
unless we optimize away a bunch of symbols...but I'd really rather not have
the linker hit a limit that requires a lot of code changes to resolve).
Rustc uses interned spans when they exceed 8 bytes, but I'd prefer to avoid
that for now. Most systems can just use on of the `PkgSymbolId` or
`ProgSymbolId` type aliases and not have to worry about it. Systems that
are actually shared between the compiler and the linker do, though, but it's
not like we don't already have a bunch of trait bounds.
Of course, as we implement link-time optimizations (LTO) in the future, it's
possible most things will need the size and I'll grow frustrated with that
and possibly revisit this. We shall see.
Anyway, this was exhausting...and...onward to the first frontend!
2021-08-02 23:54:37 -04:00
|
|
|
/// be looked up by [`SymbolId`] or if they may not yet have been
|
2020-01-14 16:26:36 -05:00
|
|
|
/// declared.
|
2022-01-14 10:21:49 -05:00
|
|
|
fn add_dep(&mut self, ident: ObjectRef, dep: ObjectRef);
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// Check whether `dep` is a dependency of `ident`.
|
2022-01-14 10:21:49 -05:00
|
|
|
fn has_dep(&self, ident: ObjectRef, dep: ObjectRef) -> bool;
|
2020-01-14 16:26:36 -05:00
|
|
|
|
|
|
|
/// Declare that `dep` is a dependency of `ident`,
|
|
|
|
/// regardless of whether they are known.
|
|
|
|
///
|
|
|
|
/// In contrast to [`add_dep`][Asg::add_dep],
|
|
|
|
/// this method will add the dependency even if one or both of `ident`
|
|
|
|
/// or `dep` have not yet been declared.
|
|
|
|
/// In such a case,
|
2020-03-14 00:10:03 -04:00
|
|
|
/// a missing identifier will be added as a placeholder,
|
2020-01-14 16:26:36 -05:00
|
|
|
/// allowing the ASG to be built with partial information as
|
|
|
|
/// identifiers continue to be discovered.
|
2020-03-26 00:43:04 -04:00
|
|
|
/// See [`IdentObjectState::declare`] for more information.
|
2020-01-14 16:26:36 -05:00
|
|
|
///
|
|
|
|
/// References to both identifiers are returned in argument order.
|
|
|
|
fn add_dep_lookup(
|
|
|
|
&mut self,
|
2021-09-23 14:52:53 -04:00
|
|
|
ident: SymbolId,
|
|
|
|
dep: SymbolId,
|
2022-01-14 10:21:49 -05:00
|
|
|
) -> (ObjectRef, ObjectRef);
|
2020-01-12 22:59:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// A [`Result`] with a hard-coded [`AsgError`] error type.
|
|
|
|
///
|
|
|
|
/// This is the result of every [`Asg`] operation that could potentially
|
|
|
|
/// fail in error.
|
2020-07-01 13:38:01 -04:00
|
|
|
pub type AsgResult<T> = Result<T, AsgError>;
|
|
|
|
|
2020-03-14 00:10:03 -04:00
|
|
|
/// Reference to an [object][super::object] stored within the [`Asg`].
|
2020-01-12 22:59:16 -05:00
|
|
|
///
|
2020-03-16 11:49:41 -04:00
|
|
|
/// IdentObject references are integer offsets,
|
2020-01-12 22:59:16 -05:00
|
|
|
/// not pointers.
|
|
|
|
/// See the [module-level documentation][self] for more information.
|
|
|
|
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq)]
|
2022-01-14 10:21:49 -05:00
|
|
|
pub struct ObjectRef(NodeIndex);
|
2020-04-09 11:34:30 -04:00
|
|
|
|
2022-01-14 10:21:49 -05:00
|
|
|
impl ObjectRef {
|
|
|
|
pub fn new(index: NodeIndex) -> Self {
|
2020-04-09 11:34:30 -04:00
|
|
|
Self(index)
|
|
|
|
}
|
|
|
|
}
|
2020-01-12 22:59:16 -05:00
|
|
|
|
2022-01-14 10:21:49 -05:00
|
|
|
impl From<NodeIndex> for ObjectRef {
|
|
|
|
fn from(index: NodeIndex) -> Self {
|
2020-01-12 22:59:16 -05:00
|
|
|
Self(index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-14 10:21:49 -05:00
|
|
|
impl From<ObjectRef> for NodeIndex {
|
|
|
|
fn from(objref: ObjectRef) -> Self {
|
2020-01-12 22:59:16 -05:00
|
|
|
objref.0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// There are currently no data stored on edges ("edge weights").
|
|
|
|
pub type AsgEdge = ();
|
|
|
|
|
|
|
|
/// Each node of the graph represents an object.
|
|
|
|
///
|
|
|
|
/// Enclosed in an [`Option`] to permit moving owned values out of the
|
|
|
|
/// graph.
|
2020-03-14 00:10:03 -04:00
|
|
|
pub type Node<O> = Option<O>;
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
/// An error from an ASG operation.
|
|
|
|
#[derive(Debug, PartialEq)]
|
2020-07-01 13:38:01 -04:00
|
|
|
pub enum AsgError {
|
2020-03-24 15:54:26 -04:00
|
|
|
/// An object could not change state in the manner requested.
|
2020-01-12 22:59:16 -05:00
|
|
|
///
|
2020-03-24 15:54:26 -04:00
|
|
|
/// See [`Asg::declare`] and [`Asg::set_fragment`] for more
|
|
|
|
/// information.
|
|
|
|
/// See also [`TransitionError`].
|
|
|
|
ObjectTransition(TransitionError),
|
2020-03-12 10:02:22 -04:00
|
|
|
|
2020-03-07 10:49:41 -05:00
|
|
|
/// The node was not expected in the current context
|
|
|
|
UnexpectedNode(String),
|
2020-01-12 22:59:16 -05:00
|
|
|
}
|
|
|
|
|
2020-07-01 13:38:01 -04:00
|
|
|
impl std::fmt::Display for AsgError {
|
2020-01-12 22:59:16 -05:00
|
|
|
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
match self {
|
2020-03-24 15:54:26 -04:00
|
|
|
Self::ObjectTransition(err) => std::fmt::Display::fmt(&err, fmt),
|
2020-03-07 10:49:41 -05:00
|
|
|
Self::UnexpectedNode(msg) => {
|
|
|
|
write!(fmt, "unexpected node: {}", msg)
|
|
|
|
}
|
2020-01-12 22:59:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 13:38:01 -04:00
|
|
|
impl std::error::Error for AsgError {
|
2020-01-12 22:59:16 -05:00
|
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
|
2020-03-24 15:54:26 -04:00
|
|
|
match self {
|
|
|
|
Self::ObjectTransition(err) => err.source(),
|
|
|
|
_ => None,
|
|
|
|
}
|
2020-01-12 22:59:16 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 13:38:01 -04:00
|
|
|
impl From<TransitionError> for AsgError {
|
2020-03-24 15:54:26 -04:00
|
|
|
fn from(err: TransitionError) -> Self {
|
|
|
|
Self::ObjectTransition(err)
|
2020-03-12 10:02:22 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-12 22:59:16 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
mod objref {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn to_from_nodeindex() {
|
|
|
|
let index = NodeIndex::<u32>::new(5);
|
2022-01-14 10:21:49 -05:00
|
|
|
let objref: ObjectRef = ObjectRef::from(index);
|
2020-01-12 22:59:16 -05:00
|
|
|
|
|
|
|
assert_eq!(index, objref.0);
|
|
|
|
assert_eq!(index, objref.into());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|