Skip to content

Commit e0ddcd9

Browse files
committed
feat: drop none literal in favour of null
Signed-off-by: Cong Wang <cwang@multikernel.io>
1 parent 814e336 commit e0ddcd9

24 files changed

Lines changed: 61 additions & 139 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ fn handle_action(action: FilterAction) -> xdp_action {
218218
// Map lookup and update patterns
219219
fn lookup_or_create(ip: IpAddress) -> Counter {
220220
var count = connection_count[ip]
221-
if (count != none) {
221+
if (count != null) {
222222
return count // Entry exists
223223
} else {
224224
connection_count[ip] = 1 // Create new entry

SPEC.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,7 +2431,7 @@ fn map_pointer_operations(flow_key: FlowKey) {
24312431
// Map lookup returns pointer to value
24322432
var flow_data = flow_map[flow_key]
24332433
2434-
if (flow_data != none) {
2434+
if (flow_data != null) {
24352435
// Direct modification through pointer
24362436
flow_data->packet_count += 1
24372437
flow_data->byte_count += packet_size
@@ -3016,7 +3016,7 @@ fn packet_filter(ctx: *xdp_md) -> action: xdp_action {
30163016
30173017
// Userspace functions with named returns
30183018
fn lookup_counter(ip: u32) -> counter_ptr: *u64 {
3019-
if (counters[ip] == none) {
3019+
if (counters[ip] == null) {
30203020
counters[ip] = 0
30213021
}
30223022
counter_ptr = &counters[ip]
@@ -3737,7 +3737,7 @@ fn security_filter(ctx: LsmContext) -> i32 {
37373737
var flow_key = extract_flow_key_from_socket(ctx)
37383738
37393739
// Check global flow statistics for threat detection
3740-
if (global_flows[flow_key] != none) {
3740+
if (global_flows[flow_key] != null) {
37413741
var flow_stats = global_flows[flow_key]
37423742
if (flow_stats.is_suspicious()) {
37433743
global_events.submit(EVENT_THREAT_DETECTED { flow_key })
@@ -4029,7 +4029,7 @@ var cache_map : hash<u32, DataCache>(1024)
40294029
@helper
40304030
fn map_lifetime_safety(key: u32) {
40314031
var cache_entry = cache_map[key]
4032-
if (cache_entry != none) {
4032+
if (cache_entry != null) {
40334033
// Compiler tracks that cache_entry is valid here
40344034
cache_entry->access_count += 1
40354035
cache_entry->last_access = bpf_ktime_get_ns()
@@ -4085,7 +4085,7 @@ fn kernel_side_processing(ctx: *xdp_md) -> xdp_action {
40854085
40864086
// Shared memory through maps - safe across contexts
40874087
var shared_buffer = shared_map[0]
4088-
if (shared_buffer != none) {
4088+
if (shared_buffer != null) {
40894089
shared_buffer->kernel_processed_count += 1
40904090
memory_copy(packet_data, shared_buffer->data, min(packet_len, 64))
40914091
}
@@ -4100,7 +4100,7 @@ fn userspace_processing() -> i32 {
41004100
41014101
// ✅ Access through shared maps
41024102
var shared_buffer = shared_map[0]
4103-
if (shared_buffer != none) {
4103+
if (shared_buffer != null) {
41044104
shared_buffer->userspace_processed_count += 1
41054105
process_shared_data(shared_buffer->data)
41064106
}

examples/map_operations_demo.ks

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ArrayElement {
5858

5959
// Safe concurrent read access - multiple programs can read simultaneously
6060
var counter = global_counter[key]
61-
if (counter != none) {
61+
if (counter != null) {
6262
// High-frequency lookup pattern - will generate optimization suggestions
6363
for (i in 0..100) {
6464
var _ = global_counter[key + i]
@@ -89,7 +89,7 @@ fn stats_updater(ctx: *__sk_buff) -> i32 {
8989

9090
// Potential write conflict with other programs
9191
var stats = shared_stats[ifindex]
92-
if (stats == none) {
92+
if (stats == null) {
9393
stats = Statistics {
9494
packet_count: 0,
9595
byte_count: 0,

examples/maps_demo.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn get_timestamp() -> u64 {
8484
}
8585

8686
// Log repeated connections
87-
if (recent_connections[src_ip] != none) {
87+
if (recent_connections[src_ip] != null) {
8888
event_log[0] = 1
8989
}
9090

examples/object_allocation.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var conn_tracker : hash<u32, *ConnStats>(1024)
2121
// Look up existing connection stats
2222
var stats = conn_tracker[src_ip]
2323

24-
if (stats == none) {
24+
if (stats == null) {
2525
// First packet from this IP - allocate new stats object
2626
stats = new ConnStats()
2727
if (stats == null) {

examples/rate_limiter.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ config network {
2121
var src_ip = 0x7F000001 // Placeholder IP (127.0.0.1)
2222

2323
// Update the count
24-
if (packet_counts[src_ip] != none) {
24+
if (packet_counts[src_ip] != null) {
2525
packet_counts[src_ip] += 1
2626
} else {
2727
packet_counts[src_ip] = 0

examples/ringbuf_demo.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn get_timestamp() -> u64 {
4444
@xdp fn network_monitor(ctx: *xdp_md) -> xdp_action {
4545
var key: u32 = 0
4646
var stat = stats[key]
47-
if (stat == none) {
47+
if (stat == null) {
4848
var init_stat = Stats { events_submitted: 0, events_dropped: 0, buffer_full_count: 0 }
4949
stats[key] = init_stat
5050
stat = stats[key]

examples/safety_demo.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ fn array_validation_demo(ctx: *xdp_md) -> xdp_action {
110110
// Safe map access
111111
var key: u32 = 1
112112
var count = packet_stats[key]
113-
if (count != none) {
113+
if (count != null) {
114114
packet_stats[key] = count + 1
115115
} else {
116116
packet_stats[key] = 1

examples/test_error_handling.ks

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn process_key(key: u32) -> u32 {
2222
try {
2323
// Check if key exists (expected absence - use null)
2424
var value = test_map[key]
25-
if (value == none) {
25+
if (value == null) {
2626
// Key doesn't exist - create default value (expected pattern)
2727
var default_value = 42
2828
test_map[key] = default_value

examples/types_demo.ks

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn extract_packet_info(ctx: *xdp_md) -> *PacketInfo {
6464
fn get_filter_action(info: PacketInfo) -> FilterAction {
6565
// Look up in the filter map
6666
var action = packet_filter[info]
67-
if (action != none) {
67+
if (action != null) {
6868
return action
6969
} else {
7070
return FILTER_ACTION_ALLOW
@@ -86,7 +86,7 @@ fn protocol_from_u8(proto_num: u8) -> Protocol {
8686
fn update_stats(info: PacketInfo) {
8787
// Update connection count
8888
var current_count = connection_count[info.src_ip]
89-
if (current_count != none) {
89+
if (current_count != null) {
9090
connection_count[info.src_ip] = current_count + 1
9191
} else {
9292
connection_count[info.src_ip] = 1
@@ -95,7 +95,7 @@ fn update_stats(info: PacketInfo) {
9595
// Update protocol stats
9696
var proto = protocol_from_u8(info.protocol)
9797
var stats = protocol_stats[proto]
98-
if (stats != none) {
98+
if (stats != null) {
9999
protocol_stats[proto] = stats + 1
100100
} else {
101101
protocol_stats[proto] = 1
@@ -107,7 +107,7 @@ fn update_stats(info: PacketInfo) {
107107
// Extract packet information
108108
var packet_info = extract_packet_info(ctx)
109109

110-
if (packet_info != none) {
110+
if (packet_info != null) {
111111
// Update statistics
112112
update_stats(*packet_info)
113113

0 commit comments

Comments
 (0)