Skip to content

Commit

Permalink
Merge branch 'master' into rust_1.74
Browse files Browse the repository at this point in the history
  • Loading branch information
thepowersgang committed Sep 21, 2024
2 parents d1a2c27 + 1827564 commit 6e31613
Show file tree
Hide file tree
Showing 17 changed files with 837 additions and 156 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
make -C tools/minicargo
make -C tools/testrunner
- name: save artefacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: binaries
path: |
Expand All @@ -41,7 +41,7 @@ jobs:
- name: avoid recompile
run: make --touch && make --touch -C tools/minicargo && make --touch -C tools/testrunner
- name: Download all workflow run artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: binaries
path: bin
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/msbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
run: msbuild /m /p:Configuration=${{env.BUILD_CONFIGURATION}} ${{env.SOLUTION_FILE_PATH}}

- name: Save Artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: binaries
# Includes `minipatch` as that's needed by the test scripts
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Download all workflow run artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4
with:
name: binaries
path: vsproject/x64/${{env.BUILD_CONFIGURATION}}
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ V ?= !
# GPROF : If set, enables the generation of a gprof annotated executable
GPROF ?=

OBJCOPY ?= objcopy
STRIP ?= strip

ifneq ($(VERBOSE),)
V :=
endif
Expand Down Expand Up @@ -170,9 +173,9 @@ else ifeq ($(shell uname -s || echo not),Darwin)
$V$(CXX) -o $@ $(LINKFLAGS) $(OBJDIR)main.o -Wl,-all_load bin/mrustc.a bin/common_lib.a $(LIBS)
else
$V$(CXX) -o $@ $(LINKFLAGS) $(OBJDIR)main.o -Wl,--whole-archive bin/mrustc.a -Wl,--no-whole-archive bin/common_lib.a $(LIBS)
objcopy --only-keep-debug $(BIN) $(BIN).debug
objcopy --add-gnu-debuglink=$(BIN).debug $(BIN)
strip $(BIN)
$(OBJCOPY) --only-keep-debug $(BIN) $(BIN).debug
$(OBJCOPY) --add-gnu-debuglink=$(BIN).debug $(BIN)
$(STRIP) $(BIN)
endif

$(OBJDIR)%.o: src/%.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/expand/asm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ namespace {
{
if(Target_GetCurSpec().m_arch.m_name == "x86_64")
return get_reg_class_x8664(sp, str);
if(Target_GetCurSpec().m_arch.m_name == "x86")
return get_reg_class_x8664(sp, str);
ERROR(sp, E0000, "Unknown architecture for asm!");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mir/check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ void MIR_Validate(const StaticTraitResolve& resolve, const ::HIR::ItemPath& path
MIR_BUG(state, "DstPtr requires a &-ptr as input, got " << ty);
}
const auto& ity = *ity_p;
if( ity.data().is_Slice() )
if( ity.data().is_Slice() || (ity.data().is_Primitive() && ity.data().as_Primitive() == HIR::CoreType::Str) )
;
else if( ity.data().is_TraitObject() )
;
Expand Down
2 changes: 1 addition & 1 deletion src/trans/codegen_mmir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ namespace
const auto* repr = Target_GetTypeRepr(sp, m_resolve, ty);
MIR_ASSERT(*m_mir_res, repr, "No repr for tuple " << ty);

bool has_drop_glue = m_resolve.type_needs_drop_glue(sp, ty);
bool has_drop_glue = m_resolve.type_needs_drop_glue(sp, ty);
auto drop_glue_path = ::HIR::Path(ty.clone(), "#drop_glue");

m_of << "type " << fmt(ty) << " {\n";
Expand Down
9 changes: 6 additions & 3 deletions tools/minicargo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ ifeq ($(OS),Windows_NT)
endif
EXESUF ?=

OBJCOPY ?= objcopy
STRIP ?= strip

V ?= @

OBJDIR := .obj/
Expand Down Expand Up @@ -41,9 +44,9 @@ $(BIN): $(OBJS) ../../bin/common_lib.a
ifeq ($(OS),Windows_NT)
else ifeq ($(shell uname -s || echo not),Darwin)
else
objcopy --only-keep-debug $(BIN) $(BIN).debug
objcopy --add-gnu-debuglink=$(BIN).debug $(BIN)
strip $(BIN)
$(OBJCOPY) --only-keep-debug $(BIN) $(BIN).debug
$(OBJCOPY) --add-gnu-debuglink=$(BIN).debug $(BIN)
$(STRIP) $(BIN)
endif

$(OBJDIR)%.o: %.cpp
Expand Down
13 changes: 13 additions & 0 deletions tools/mir_opt_test/main_miropt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <trans/monomorphise.hpp> // used as a MIR clone
#include <debug_inner.hpp>
#include <mir/visit_crate_mir.hpp>
#include <trans/codegen.hpp>

#ifdef _WIN32
# define NOGDI // Don't include GDI functions (defines some macros that collide with mrustc ones)
Expand Down Expand Up @@ -71,6 +72,18 @@ int main(int argc, char* argv[])
MIR_OptimiseCrate(*file->m_crate, false);
}

TransList tl;
{
auto ph = DebugTimedPhase("Enumerate");
tl = Trans_Enumerate_Public(*file->m_crate);
}
TransOptions opt;
opt.mode = "monomir";
{
auto ph = DebugTimedPhase("Codegen");
Trans_Codegen(opts.output, CodegenOutput::Object, opt, *file->m_crate, tl, "");
}

return 0;
}

Expand Down
59 changes: 49 additions & 10 deletions tools/mir_opt_test/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,18 +95,50 @@ MirOptTestFile MirOptTestFile::load_from_file(const helpers::path& p)
GET_CHECK_TOK(tok, lex, TOK_COLON);
auto type = parse_type(lex);
GET_CHECK_TOK(tok, lex, TOK_EQUAL);
GET_CHECK_TOK(tok, lex, TOK_STRING);
EncodedLiteral value;
for(auto b : tok.str())
value.bytes.push_back(b);
if( consume_if(lex, TOK_BRACE_OPEN) ) {
TODO(lex.point_span(), "static - relocations");
}
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);

auto st_decl = ::HIR::Static(HIR::Linkage(), is_mut, std::move(type), HIR::ExprPtr());
st_decl.m_value_res = std::move(value);
st_decl.m_value_generated = true;

if( consume_if(lex, TOK_AT) ) {
GET_CHECK_TOK(tok, lex, TOK_STRING);
st_decl.m_linkage.name = tok.str();
}
else {
GET_CHECK_TOK(tok, lex, TOK_STRING);
EncodedLiteral value;
for(auto b : tok.str())
value.bytes.push_back(b);
if( consume_if(lex, TOK_BRACE_OPEN) ) {
while( lex.lookahead(0) != TOK_BRACE_CLOSE ) {
GET_CHECK_TOK(tok, lex, TOK_AT);
GET_CHECK_TOK(tok, lex, TOK_INTEGER);
auto ofs = tok.intval();
GET_CHECK_TOK(tok, lex, TOK_PLUS);
GET_CHECK_TOK(tok, lex, TOK_INTEGER);
auto len = tok.intval();
GET_CHECK_TOK(tok, lex, TOK_EQUAL);

GET_TOK(tok, lex);
if( tok.type() == TOK_IDENT ) {
auto path = ::HIR::SimplePath("", { tok.ident().name });
value.relocations.push_back(Reloc::new_named(ofs.get_lo(), len.get_lo(), path));
}
else if( tok.type() == TOK_STRING ) {
value.relocations.push_back(Reloc::new_bytes(ofs.get_lo(), len.get_lo(), tok.str()));
}
else {
ERROR(lex.point_span(), E0000, "Expected ident or string");
}
if( !consume_if(lex, TOK_COMMA) ) {
continue;
}
}
GET_CHECK_TOK(tok, lex, TOK_BRACE_CLOSE);
}

st_decl.m_value_res = std::move(value);
st_decl.m_value_generated = true;
}
GET_CHECK_TOK(tok, lex, TOK_SEMICOLON);
auto vi = ::HIR::VisEnt<HIR::ValueItem> {
HIR::Publicity::new_global(), ::HIR::ValueItem(mv$(st_decl))
};
Expand Down Expand Up @@ -193,6 +225,7 @@ MirOptTestFile MirOptTestFile::load_from_file(const helpers::path& p)
str_fields.push_back(HIR::VisEnt<HIR::TypeRef>{ HIR::Publicity::new_global(), f.ty.clone() });
}
auto str = HIR::Struct(HIR::GenericParams(), HIR::Struct::Repr::C, mv$(str_fields));
str.m_markings.is_copy = true;
auto vi = ::HIR::VisEnt<HIR::TypeItem> {
HIR::Publicity::new_global(), ::HIR::TypeItem(mv$(str))
};
Expand All @@ -208,6 +241,7 @@ MirOptTestFile MirOptTestFile::load_from_file(const helpers::path& p)
for(const auto& f : repr.fields) {
unn.m_variants.push_back(std::make_pair( RcString(), HIR::VisEnt<HIR::TypeRef>{ HIR::Publicity::new_global(), f.ty.clone() } ));
}
unn.m_markings.is_copy = true;
auto vi = ::HIR::VisEnt<HIR::TypeItem> {
HIR::Publicity::new_global(), ::HIR::TypeItem(mv$(unn))
};
Expand Down Expand Up @@ -591,6 +625,11 @@ namespace {
auto r = parse_param(lex, val_name_map);
src = MIR::RValue::make_BinOp({ mv$(l), op, mv$(r) });
}
else if( tok.ident() == "DSTPTR" )
{
auto v = parse_lvalue(lex, val_name_map);
src = MIR::RValue::make_DstPtr({ mv$(v) });
}
else if( consume_if(lex, TOK_PAREN_OPEN) )
{
auto parse_binop = [&](TokenStream& lex, MIR::eBinOp op) {
Expand Down
24 changes: 24 additions & 0 deletions tools/standalone_miri/hir_sim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ namespace HIR {
friend ::std::ostream& operator<<(::std::ostream& os, const ArraySize& x) {
return os << x.count;
}
Ordering ord(const ArraySize& x) const {
return ::ord(count, x.count);
}
bool operator<(const ArraySize& o) const { return count < o.count; }
bool operator==(const ArraySize& o) const { return count == o.count; }
bool operator!=(const ArraySize& o) const { return count != o.count; }
};

/// Definition of a type
Expand Down Expand Up @@ -239,6 +244,20 @@ namespace HIR {
::std::vector<TypeRef> tys;

friend ::std::ostream& operator<<(::std::ostream& os, const PathParams& x);

Ordering ord(const PathParams& x) const {
__ORD(tys);
return OrdEqual;
}
bool operator==(const PathParams& x) const {
return this->ord(x) == OrdEqual;
}
bool operator!=(const PathParams& x) const {
return this->ord(x) != OrdEqual;
}
bool operator<(const PathParams& x) const {
return this->ord(x) == OrdLess;
}
};

struct Path {
Expand All @@ -257,6 +276,11 @@ namespace HIR {
struct GenericPath {
RcString n;

Ordering ord(const GenericPath& x) const {
return ::ord(n, x.n);
}
bool operator==(const GenericPath& p) const { return ord(p) == OrdEqual; }
bool operator!=(const GenericPath& p) const { return ord(p) != OrdEqual; }
friend ::std::ostream& operator<<(::std::ostream& os, const GenericPath& x){
return os << x.n;
}
Expand Down
Loading

0 comments on commit 6e31613

Please sign in to comment.