Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mac-os regression in apply generic arguments to method calls #1632

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion gcc/rust/hir/tree/rust-hir-expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1872,7 +1872,8 @@ class MethodCallExpr : public ExprWithoutBlock

std::unique_ptr<Expr> &get_receiver () { return receiver; }

PathExprSegment get_method_name () const { return method_name; };
PathExprSegment &get_method_name () { return method_name; };
const PathExprSegment &get_method_name () const { return method_name; };

size_t num_params () const { return params.size (); }

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/hir/tree/rust-hir-full-decls.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PathExpr;
// rust-path.h
class PathIdentSegment;
struct GenericArgsBinding;
struct GenericArgs;
class GenericArgs;
class PathExprSegment;
class PathPattern;
class PathInExpression;
Expand Down
37 changes: 28 additions & 9 deletions gcc/rust/hir/tree/rust-hir-path.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ class ConstGenericArg
Location locus;
};

// Generic arguments allowed in each path expression segment - inline?
struct GenericArgs
class GenericArgs
{
std::vector<Lifetime> lifetime_args;
std::vector<std::unique_ptr<Type> > type_args;
Expand Down Expand Up @@ -172,6 +171,7 @@ struct GenericArgs
: lifetime_args (other.lifetime_args), binding_args (other.binding_args),
const_args (other.const_args), locus (other.locus)
{
type_args.clear ();
type_args.reserve (other.type_args.size ());

for (const auto &e : other.type_args)
Expand All @@ -188,6 +188,7 @@ struct GenericArgs
const_args = other.const_args;
locus = other.locus;

type_args.clear ();
type_args.reserve (other.type_args.size ());
for (const auto &e : other.type_args)
type_args.push_back (e->clone_type ());
Expand Down Expand Up @@ -235,26 +236,44 @@ class PathExprSegment
Location locus;

public:
// Returns true if there are any generic arguments
bool has_generic_args () const { return generic_args.has_generic_args (); }

// Constructor for segment (from IdentSegment and GenericArgs)
PathExprSegment (Analysis::NodeMapping mappings,
PathIdentSegment segment_name, Location locus = Location (),
GenericArgs generic_args = GenericArgs::create_empty ())
PathIdentSegment segment_name, Location locus,
GenericArgs generic_args)
: mappings (std::move (mappings)), segment_name (std::move (segment_name)),
generic_args (std::move (generic_args)), locus (locus)
{}

PathExprSegment (PathExprSegment const &other)
: mappings (other.mappings), segment_name (other.segment_name),
generic_args (other.generic_args), locus (other.locus)
{}

PathExprSegment &operator= (PathExprSegment const &other)
{
mappings = other.mappings;
segment_name = other.segment_name;
generic_args = other.generic_args;
locus = other.locus;

return *this;
}

// move constructors
PathExprSegment (PathExprSegment &&other) = default;
PathExprSegment &operator= (PathExprSegment &&other) = default;

std::string as_string () const;

Location get_locus () const { return locus; }

PathIdentSegment get_segment () const { return segment_name; }
PathIdentSegment &get_segment () { return segment_name; }
const PathIdentSegment &get_segment () const { return segment_name; }

GenericArgs &get_generic_args () { return generic_args; }

const Analysis::NodeMapping &get_mappings () const { return mappings; }

bool has_generic_args () const { return generic_args.has_generic_args (); }
};

// HIR node representing a pattern that involves a "path" - abstract base class
Expand Down
5 changes: 3 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1149,10 +1149,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
// apply any remaining generic arguments
if (expr.get_method_name ().has_generic_args ())
{
rust_debug_loc (expr.get_method_name ().get_generic_args ().get_locus (),
HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();
rust_debug_loc (args.get_locus (),
"applying generic arguments to method_call: {%s}",
lookup->debug_str ().c_str ());
HIR::GenericArgs &args = expr.get_method_name ().get_generic_args ();

lookup
= SubstMapper::Resolve (lookup, expr.get_method_name ().get_locus (),
&args);
Expand Down
4 changes: 4 additions & 0 deletions gcc/rust/typecheck/rust-tyty.h
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,10 @@ class SubstitutionArgumentMappings
return *this;
}

SubstitutionArgumentMappings (SubstitutionArgumentMappings &&other) = default;
SubstitutionArgumentMappings &operator= (SubstitutionArgumentMappings &&other)
= default;

static SubstitutionArgumentMappings error ()
{
return SubstitutionArgumentMappings ({}, Location (), nullptr, false);
Expand Down
15 changes: 8 additions & 7 deletions gcc/testsuite/rust/debug/chartype.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// 'char' should use DW_ATE_UTF
fn main () {
let c = 'x';
// { dg-do compile }
// Use -w to avoid warnings about the unused variables
// DW_ATE_UTF entered in DWARF 4.
// { dg-skip-if "see https://github.com/Rust-GCC/gccrs/pull/1632" { *-*-darwin* } }
// { dg-options "-w -gdwarf-4 -dA" }
// DW_ATE_UTF = 0x10
// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
// 'char' should use DW_ATE_UTF
fn main() {
let c = 'x';
// Use -w to avoid warnings about the unused variables
// DW_ATE_UTF entered in DWARF 4.
// DW_ATE_UTF = 0x10
// { dg-final { scan-assembler "0x10\[ \t]\[^\n\r]* DW_AT_encoding" } } */
}