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

Respect lack of public annotations for colon-refs #1546

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion xls/dslx/frontend/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "absl/strings/str_format.h"
#include "absl/types/span.h"
#include "absl/types/variant.h"
#include "xls/common/casts.h"
#include "xls/common/status/status_macros.h"
#include "xls/dslx/channel_direction.h"
#include "xls/dslx/frontend/ast_node.h" // IWYU pragma: export
Expand Down
6 changes: 3 additions & 3 deletions xls/dslx/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ absl::StatusOr<Function*> Parser::ParseProcNext(
// type.
absl::StatusOr<Function*> Parser::ParseProcInit(
Bindings& bindings, std::vector<ParametricBinding*> parametric_bindings,
std::string_view proc_name) {
std::string_view proc_name, bool is_public) {
Bindings inner_bindings(&bindings);
XLS_ASSIGN_OR_RETURN(Token init_identifier, PopToken());
if (!init_identifier.IsIdentifier("init")) {
Expand All @@ -2369,7 +2369,7 @@ absl::StatusOr<Function*> Parser::ParseProcInit(
Function* init = module_->Make<Function>(
span, name_def, std::move(parametric_bindings), std::vector<Param*>(),
/*return_type=*/nullptr, body, FunctionTag::kProcInit,
/*is_public=*/false);
/*is_public=*/is_public);
name_def->set_definer(init);
return init;
}
Expand Down Expand Up @@ -2494,7 +2494,7 @@ absl::StatusOr<T*> Parser::ParseProcLike(bool is_public,

XLS_ASSIGN_OR_RETURN(Function * init,
ParseProcInit(member_bindings, parametric_bindings,
name_def->identifier()));
name_def->identifier(), is_public));
proc_like_body.init = init;
XLS_RETURN_IF_ERROR(module_->AddTop(init, MakeModuleTopCollisionError));

Expand Down
2 changes: 1 addition & 1 deletion xls/dslx/frontend/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ class Parser : public TokenParser {

absl::StatusOr<Function*> ParseProcInit(
Bindings& bindings, std::vector<ParametricBinding*> parametric_bindings,
std::string_view proc_name);
std::string_view proc_name, bool is_public);

// Parses a proc-like entity (i.e. either a Proc or a Block).
template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions xls/dslx/stdlib/std.x
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ fn smul_test() {
// If dividing by `0`, returns all `1`s for quotient and `n` for remainder.
// Implements binary long division; should be expected to use a large number of gates and have a slow
// critical path when using combinational codegen.
fn iterative_div_mod<N: u32, M: u32>(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) {
pub fn iterative_div_mod<N: u32, M: u32>(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) {
// Zero extend divisor by 1 bit.
let divisor = d as uN[M + u32:1];

Expand All @@ -223,7 +223,7 @@ fn iterative_div_mod<N: u32, M: u32>(n: uN[N], d: uN[M]) -> (uN[N], uN[M]) {

// Returns unsigned division of `n` (N bits) and `d` (M bits) as quotient (N bits).
// If dividing by `0`, returns all `1`s for quotient.
fn iterative_div<N: u32, M: u32>(n: uN[N], d: uN[M]) -> uN[N] {
pub fn iterative_div<N: u32, M: u32>(n: uN[N], d: uN[M]) -> uN[N] {
let (q, r) = iterative_div_mod(n, d);
q
}
Expand Down
8 changes: 8 additions & 0 deletions xls/dslx/tests/errors/error_modules_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,14 @@ def test_nominal_type_mismatch(self):
'vs .*/dslx/tests/errors/mod_simple_struct_duplicate.x:MyStruct {}\n',
)

def test_imports_and_calls_private_parametric(self):
stderr = self._run(
'xls/dslx/tests/errors/imports_and_calls_private_parametric.x'
)
self.assertIn(
'Attempted to resolve a module member that was not public', stderr
)


if __name__ == '__main__':
test_base.main()
24 changes: 24 additions & 0 deletions xls/dslx/tests/errors/imports_and_calls_private_parametric.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2024 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import xls.dslx.tests.errors.mod_private_parametric;

fn main() -> u32 {
mod_private_parametric::p<u32:32>()
}

#[test]
fn test_main() {
assert_eq(main(), u32:0)
}
18 changes: 18 additions & 0 deletions xls/dslx/tests/errors/mod_private_parametric.x
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2024 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Note: this does not have a pub annotation.
fn p<N: u32>() -> bits[N] {
bits[N]:0
}
14 changes: 12 additions & 2 deletions xls/dslx/type_system/deduce_invocation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,18 @@ static absl::StatusOr<Function*> ResolveColonRefToFnForInvocation(
ctx->type_info()->GetImported(*import);
XLS_RET_CHECK(imported_info.has_value());
Module* module = imported_info.value()->module;
return GetMemberOrTypeInferenceError<Function>(module, ref->attr(),
ref->span());
XLS_ASSIGN_OR_RETURN(Function * resolved,
GetMemberOrTypeInferenceError<Function>(
module, ref->attr(), ref->span()));
if (!resolved->is_public()) {
return TypeInferenceErrorStatus(
ref->span(), nullptr,
absl::StrFormat("Attempted to resolve a module member that was not "
"public; `%s` defined in module `%s` @ %s",
resolved->identifier(), module->name(),
resolved->span().ToString()));
}
return resolved;
}

absl::StatusOr<TypeAndParametricEnv> DeduceInstantiation(
Expand Down
1 change: 0 additions & 1 deletion xls/examples/fp32_fmac.x
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ proc fp32_fmac {
config(input_a: chan<F32> in, input_b: chan<F32> in,
reset: chan<bool> in, output: chan<F32> out) {
spawn apfloat_fmac::fmac<u32:8, u32:23>(input_a, input_b, reset, output);
()
}

// Nothing to do here - the spawned fmac does all the lifting.
Expand Down
3 changes: 2 additions & 1 deletion xls/examples/lfsr.x
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
// in a 5-bit LFSR with taps on bits 2 and 4.
////////////////////////////////////////////////////////////////////////////////

fn lfsr<BIT_WIDTH: u32>(current_value: uN[BIT_WIDTH], tap_mask: uN[BIT_WIDTH]) -> uN[BIT_WIDTH] {
pub fn lfsr<BIT_WIDTH: u32>
(current_value: uN[BIT_WIDTH], tap_mask: uN[BIT_WIDTH]) -> uN[BIT_WIDTH] {
// Compute the new bit from the taps
let new_bit = for (index, xor_bit): (u32, u1) in range(u32:0, BIT_WIDTH) {
if tap_mask[index+:u1] == u1:0 { xor_bit } else { xor_bit ^ current_value[index+:u1] }
Expand Down
4 changes: 2 additions & 2 deletions xls/examples/ram.x
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn num_partitions(word_partition_size: u32, data_width: u32) -> u32 {
// ASSERT_VALID_READ: if true, add assertion that read operations are only
// performed on values that a previous write has set. This is meant to model
// asserting that a user doesn't read X from an unitialized SRAM.
proc RamModel<DATA_WIDTH:u32, SIZE:u32, WORD_PARTITION_SIZE:u32={u32:0},
pub proc RamModel<DATA_WIDTH:u32, SIZE:u32, WORD_PARTITION_SIZE:u32={u32:0},
SIMULTANEOUS_READ_WRITE_BEHAVIOR:SimultaneousReadWriteBehavior=
{SimultaneousReadWriteBehavior::READ_BEFORE_WRITE},
INITIALIZED:bool={false},
Expand Down Expand Up @@ -503,7 +503,7 @@ pub struct RWRamResp<DATA_WIDTH:u32> {
}

// Models a single-port RAM.
proc SinglePortRamModel<DATA_WIDTH:u32, SIZE:u32,
pub proc SinglePortRamModel<DATA_WIDTH:u32, SIZE:u32,
WORD_PARTITION_SIZE:u32={u32:0},
ADDR_WIDTH:u32={std::clog2(SIZE)},
NUM_PARTITIONS:u32={num_partitions(WORD_PARTITION_SIZE, DATA_WIDTH)}> {
Expand Down
2 changes: 1 addition & 1 deletion xls/examples/sobel_filter.x
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Y_STENCIL_F32 = map(Y_STENCIL, convert_triplet);

// Apply a stencil 'stencil' on the image 'in_img' to calculate the pixel
// at row 'row_idx', column 'col_idx' in the output image.
fn apply_stencil_float32<NUM_ROWS:u32, NUM_COLS:u32, NUM_ELMS:u32 = {NUM_ROWS*NUM_COLS}>(
pub fn apply_stencil_float32<NUM_ROWS:u32, NUM_COLS:u32, NUM_ELMS:u32 = {NUM_ROWS*NUM_COLS}>(
in_img: F32[NUM_ELMS],
row_idx:u32, col_idx:u32, stencil: F32[3][3]) -> F32 {

Expand Down
2 changes: 1 addition & 1 deletion xls/modules/zstd/block_dec.x
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type SequenceExecutorMessageType = common::SequenceExecutorMessageType;
// │ └───────────────────┘ │
// └───────────────────────────────────────┘

proc BlockDecoder {
pub proc BlockDecoder {
input_r: chan<BlockDataPacket> in;
output_s: chan<SequenceExecutorPacket> out;

Expand Down
2 changes: 1 addition & 1 deletion xls/modules/zstd/ram_printer.x
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum RamPrinterStatus : u2 {

struct RamPrinterState<ADDR_WIDTH: u32> { status: RamPrinterStatus, addr: bits[ADDR_WIDTH] }

proc RamPrinter<DATA_WIDTH: u32, SIZE: u32, NUM_PARTITIONS: u32, ADDR_WIDTH: u32, NUM_MEMORIES: u32>
pub proc RamPrinter<DATA_WIDTH: u32, SIZE: u32, NUM_PARTITIONS: u32, ADDR_WIDTH: u32, NUM_MEMORIES: u32>
{
print_r: chan<()> in;
finish_s: chan<()> out;
Expand Down
2 changes: 1 addition & 1 deletion xls/modules/zstd/repacketizer.x
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const ZERO_ZSTD_DECODED_PACKET = zero!<ZstdDecodedPacket>();
const ZERO_REPACKETIZER_STATE = zero!<RepacketizerState>();
const INIT_REPACKETIZER_STATE = RepacketizerState {to_fill: DATA_WIDTH, ..ZERO_REPACKETIZER_STATE};

proc Repacketizer {
pub proc Repacketizer {
input_r: chan<ZstdDecodedPacket> in;
output_s: chan<ZstdDecodedPacket> out;

Expand Down
2 changes: 1 addition & 1 deletion xls/modules/zstd/sequence_executor.x
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ fn handle_reapeated_offset_for_sequences
(seq, final_repeat_offsets)
}

proc SequenceExecutor<HISTORY_BUFFER_SIZE_KB: u32,
pub proc SequenceExecutor<HISTORY_BUFFER_SIZE_KB: u32,
RAM_SIZE: u32 = {ram_size(HISTORY_BUFFER_SIZE_KB)},
RAM_ADDR_WIDTH: u32 = {ram_addr_width(HISTORY_BUFFER_SIZE_KB)},
INIT_HB_PTR_ADDR: u32 = {u32:0}, INIT_HB_PTR_RAM: u32 = {u32:0},
Expand Down
Loading