Skip to content

Commit

Permalink
test: adds test for visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra committed Oct 29, 2020
1 parent a435b5e commit 56530c0
Show file tree
Hide file tree
Showing 34 changed files with 715 additions and 359 deletions.
2 changes: 2 additions & 0 deletions crates/mun_codegen/src/ir/body.rs
Expand Up @@ -560,6 +560,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
match resolver
.resolve_path_as_value_fully(self.db.upcast(), path)
.expect("unknown path")
.0
{
ValueNs::LocalBinding(pat) => {
if let Some(param) = self.pat_to_param.get(&pat) {
Expand Down Expand Up @@ -606,6 +607,7 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
match resolver
.resolve_path_as_value_fully(self.db.upcast(), path)
.expect("unknown path")
.0
{
ValueNs::LocalBinding(pat) => *self
.pat_to_local
Expand Down
13 changes: 7 additions & 6 deletions crates/mun_codegen/src/ir/file_group.rs
Expand Up @@ -3,10 +3,11 @@ use super::{
intrinsics,
type_table::{TypeTable, TypeTableBuilder},
};
use crate::code_gen::CodeGenContext;
use crate::value::{IrTypeContext, IrValueContext};
use hir::HasVisibility;
use hir::ModuleDef;
use crate::{
code_gen::CodeGenContext,
value::{IrTypeContext, IrValueContext},
};
use hir::{HasVisibility, ModuleDef};
use inkwell::{module::Module, types::PointerType, values::UnnamedAddress, AddressSpace};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -66,7 +67,7 @@ pub(crate) fn gen_file_group_ir<'db, 'ink>(
ModuleDef::Module(_) => (),
ModuleDef::Function(_) => (), // TODO: Extern types?
ModuleDef::Struct(_) => (),
ModuleDef::BuiltinType(_) => (),
ModuleDef::PrimitiveType(_) => (),
ModuleDef::TypeAlias(_) => (),
}
}
Expand Down Expand Up @@ -121,7 +122,7 @@ pub(crate) fn gen_file_group_ir<'db, 'ink>(
ModuleDef::Function(f) => {
type_table_builder.collect_fn(f);
}
ModuleDef::BuiltinType(_) | ModuleDef::TypeAlias(_) | ModuleDef::Module(_) => (),
ModuleDef::PrimitiveType(_) | ModuleDef::TypeAlias(_) | ModuleDef::Module(_) => (),
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/mun_codegen/src/ir/intrinsics.rs
Expand Up @@ -57,7 +57,8 @@ fn collect_expr<'db, 'ink>(

if let Expr::Path(path) = expr {
let resolver = hir::resolver_for_expr(db.upcast(), body.owner(), expr_id);
if let Some(ValueNs::StructId(_)) = resolver.resolve_path_as_value_fully(db.upcast(), path)
if let Some((ValueNs::StructId(_), _)) =
resolver.resolve_path_as_value_fully(db.upcast(), path)
{
collect_intrinsic(context, &target, &intrinsics::new, intrinsics);
// self.collect_intrinsic( module, entries, &intrinsics::drop);
Expand Down
3 changes: 2 additions & 1 deletion crates/mun_compiler/src/driver.rs
Expand Up @@ -266,7 +266,8 @@ impl Driver {
self.assembly_output_path_from_file(file_id)
}

/// Writes all assemblies
/// Writes all assemblies. If `force` is false, the binary will not be written if there are no
/// changes since last time it was written.
pub fn write_all_assemblies(&mut self, force: bool) -> Result<(), anyhow::Error> {
// Create a copy of all current files
for package in mun_hir::Package::all(self.db.upcast()) {
Expand Down
1 change: 1 addition & 0 deletions crates/mun_compiler_daemon/src/lib.rs
Expand Up @@ -65,6 +65,7 @@ pub fn compile_and_watch_manifest(
// Simply remove the source file from the source root
let relative_path = compute_source_relative_path(&source_directory, path)?;
log::info!("Removing {}", relative_path);
// TODO: Remove assembly files if there are no files referencing it.
// let assembly_path = driver.assembly_output_path(driver.get_file_id_for_path(&relative_path).expect("cannot remove a file that was not part of the compilation in the first place"));
// if assembly_path.is_file() {
// std::fs::remove_file(assembly_path)?;
Expand Down
157 changes: 0 additions & 157 deletions crates/mun_hir/src/builtin_type.rs

This file was deleted.

12 changes: 6 additions & 6 deletions crates/mun_hir/src/code_model/module.rs
@@ -1,6 +1,6 @@
use super::{Function, Package, Struct, TypeAlias};
use crate::builtin_type::BuiltinType;
use crate::ids::{ItemDefinitionId, ModuleId};
use crate::primitive_type::PrimitiveType;
use crate::{DiagnosticSink, FileId, HirDatabase};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Module {
pub enum ModuleDef {
Module(Module),
Function(Function),
BuiltinType(BuiltinType),
PrimitiveType(PrimitiveType),
Struct(Struct),
TypeAlias(TypeAlias),
}
Expand All @@ -71,9 +71,9 @@ impl From<Function> for ModuleDef {
}
}

impl From<BuiltinType> for ModuleDef {
fn from(t: BuiltinType) -> Self {
ModuleDef::BuiltinType(t)
impl From<PrimitiveType> for ModuleDef {
fn from(t: PrimitiveType) -> Self {
ModuleDef::PrimitiveType(t)
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ impl From<ItemDefinitionId> for ModuleDef {
ItemDefinitionId::FunctionId(id) => Function { id }.into(),
ItemDefinitionId::StructId(id) => Struct { id }.into(),
ItemDefinitionId::TypeAliasId(id) => TypeAlias { id }.into(),
ItemDefinitionId::BuiltinType(id) => id.into(),
ItemDefinitionId::PrimitiveType(id) => id.into(),
}
}
}
4 changes: 3 additions & 1 deletion crates/mun_hir/src/code_model/package.rs
Expand Up @@ -9,8 +9,10 @@ pub struct Package {
}

impl Package {
/// Returns the root package
/// Returns all the packages defined in the database
pub fn all(_db: &dyn HirDatabase) -> Vec<Package> {
// TODO: Currently we assume there is only a single package with ID 0. This has to be
// implemented when have multiple packages. See CrateGraph in rust-analyzer.
vec![Package { id: PackageId(0) }]
}

Expand Down
6 changes: 5 additions & 1 deletion crates/mun_hir/src/db.rs
Expand Up @@ -50,7 +50,7 @@ pub trait SourceDatabase: salsa::Database {
#[salsa::input]
fn package_source_root(&self, package: PackageId) -> SourceRootId;

/// For a package returns the hierarchy of modules
/// For a package, returns its hierarchy of modules.
#[salsa::invoke(ModuleTree::module_tree_query)]
fn module_tree(&self, package: PackageId) -> Arc<ModuleTree>;

Expand Down Expand Up @@ -86,6 +86,8 @@ pub trait InternDatabase: SourceDatabase {

#[salsa::query_group(DefDatabaseStorage)]
pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
/// Returns the `ItemTree` for a specific file. An `ItemTree` represents all the top level
/// declarations within a file.
#[salsa::invoke(item_tree::ItemTree::item_tree_query)]
fn item_tree(&self, file_id: FileId) -> Arc<ItemTree>;

Expand All @@ -98,6 +100,8 @@ pub trait DefDatabase: InternDatabase + AstDatabase + Upcast<dyn AstDatabase> {
#[salsa::invoke(crate::FunctionData::fn_data_query)]
fn fn_data(&self, func: FunctionId) -> Arc<FunctionData>;

/// Returns the `PackageDefs` for the specified `PackageId`. The `PackageDefs` contains all
/// resolved items defined for every module in the package.
#[salsa::invoke(crate::package_defs::PackageDefs::package_def_map_query)]
fn package_defs(&self, package_id: PackageId) -> Arc<PackageDefs>;

Expand Down
20 changes: 20 additions & 0 deletions crates/mun_hir/src/diagnostics.rs
Expand Up @@ -137,6 +137,26 @@ impl Diagnostic for CyclicType {
}
}

#[derive(Debug)]
pub struct PrivateAccess {
pub file: FileId,
pub expr: SyntaxNodePtr,
}

impl Diagnostic for PrivateAccess {
fn message(&self) -> String {
"access of private type".to_string()
}

fn source(&self) -> InFile<SyntaxNodePtr> {
InFile::new(self.file, self.expr)
}

fn as_any(&self) -> &(dyn Any + Send + 'static) {
self
}
}

#[derive(Debug)]
pub struct ExpectedFunction {
pub file: FileId,
Expand Down

0 comments on commit 56530c0

Please sign in to comment.