implements PR-09.1: remove moduleKey from FE/BE contracts
This commit is contained in:
-32
@@ -15,7 +15,6 @@ import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
@@ -108,12 +107,10 @@ public class IRBackend {
|
||||
final var signature = localCallableSignatures.get(i);
|
||||
final var remappedModuleId = remapModuleId(
|
||||
signature.moduleId(),
|
||||
signature.moduleKey(),
|
||||
moduleRemap,
|
||||
"callable signature");
|
||||
remap[i] = callableTable.register(
|
||||
remappedModuleId,
|
||||
signature.moduleKey(),
|
||||
signature.callableName(),
|
||||
signature.arity(),
|
||||
signature.typeShape());
|
||||
@@ -129,7 +126,6 @@ public class IRBackend {
|
||||
final var remappedInstructions = new ArrayList<IRBackendExecutableFunction.Instruction>(function.instructions().size());
|
||||
final var remappedFunctionModuleId = remapModuleId(
|
||||
function.moduleId(),
|
||||
function.moduleKey(),
|
||||
moduleRemap,
|
||||
"function");
|
||||
for (final var instruction : function.instructions()) {
|
||||
@@ -151,13 +147,11 @@ public class IRBackend {
|
||||
}
|
||||
final var remappedCalleeModuleId = remapModuleId(
|
||||
instruction.calleeModuleId(),
|
||||
instruction.calleeModuleKey(),
|
||||
moduleRemap,
|
||||
"callee");
|
||||
remappedInstructions.add(new IRBackendExecutableFunction.Instruction(
|
||||
instruction.kind(),
|
||||
remappedCalleeModuleId,
|
||||
instruction.calleeModuleKey(),
|
||||
instruction.calleeCallableName(),
|
||||
remappedCallee,
|
||||
instruction.hostCall(),
|
||||
@@ -171,7 +165,6 @@ public class IRBackend {
|
||||
return new IRBackendExecutableFunction(
|
||||
function.fileId(),
|
||||
remappedFunctionModuleId,
|
||||
function.moduleKey(),
|
||||
function.callableName(),
|
||||
remapCallableId(function.callableId(), callableRemap, "function"),
|
||||
function.sourceStart(),
|
||||
@@ -186,7 +179,6 @@ public class IRBackend {
|
||||
|
||||
private ModuleId remapModuleId(
|
||||
final ModuleId localModuleId,
|
||||
final String moduleKey,
|
||||
final ModuleId[] moduleRemap,
|
||||
final String label) {
|
||||
if (localModuleId != null && !localModuleId.isNone()) {
|
||||
@@ -196,33 +188,9 @@ public class IRBackend {
|
||||
}
|
||||
return moduleRemap[localIndex];
|
||||
}
|
||||
final var fallbackReference = moduleReferenceFromKey(moduleKey);
|
||||
if (fallbackReference != null) {
|
||||
return moduleTable.register(fallbackReference);
|
||||
}
|
||||
return ModuleId.none();
|
||||
}
|
||||
|
||||
private ModuleReference moduleReferenceFromKey(final String moduleKey) {
|
||||
if (moduleKey == null || moduleKey.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
final var separator = moduleKey.indexOf(':');
|
||||
if (separator <= 0) {
|
||||
return null;
|
||||
}
|
||||
final var project = moduleKey.substring(0, separator).trim();
|
||||
final var rawPath = moduleKey.substring(separator + 1).trim();
|
||||
if (project.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
if (rawPath.isBlank()) {
|
||||
return new ModuleReference(project, ReadOnlyList.empty());
|
||||
}
|
||||
final var segments = List.of(rawPath.split("/"));
|
||||
return new ModuleReference(project, ReadOnlyList.wrap(segments));
|
||||
}
|
||||
|
||||
private CallableId remapCallableId(
|
||||
final CallableId localCallableId,
|
||||
final CallableId[] callableRemap,
|
||||
|
||||
+9
-24
@@ -12,7 +12,6 @@ import java.util.Objects;
|
||||
public record IRBackendExecutableFunction(
|
||||
FileId fileId,
|
||||
ModuleId moduleId,
|
||||
String moduleKey,
|
||||
String callableName,
|
||||
CallableId callableId,
|
||||
int sourceStart,
|
||||
@@ -26,7 +25,6 @@ public record IRBackendExecutableFunction(
|
||||
|
||||
public IRBackendExecutableFunction(
|
||||
final FileId fileId,
|
||||
final String moduleKey,
|
||||
final String callableName,
|
||||
final CallableId callableId,
|
||||
final int sourceStart,
|
||||
@@ -40,7 +38,6 @@ public record IRBackendExecutableFunction(
|
||||
this(
|
||||
fileId,
|
||||
ModuleId.none(),
|
||||
moduleKey,
|
||||
callableName,
|
||||
callableId,
|
||||
sourceStart,
|
||||
@@ -59,7 +56,6 @@ public record IRBackendExecutableFunction(
|
||||
if (!moduleId.isNone()) {
|
||||
moduleId.getIndex();
|
||||
}
|
||||
moduleKey = moduleKey == null ? "" : moduleKey;
|
||||
callableName = Objects.requireNonNull(callableName, "callableName");
|
||||
if (callableName.isBlank()) {
|
||||
throw new IllegalArgumentException("callableName must not be blank");
|
||||
@@ -88,7 +84,6 @@ public record IRBackendExecutableFunction(
|
||||
public record Instruction(
|
||||
InstructionKind kind,
|
||||
ModuleId calleeModuleId,
|
||||
String calleeModuleKey,
|
||||
String calleeCallableName,
|
||||
CallableId calleeCallableId,
|
||||
HostCallMetadata hostCall,
|
||||
@@ -101,19 +96,17 @@ public record IRBackendExecutableFunction(
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final ModuleId calleeModuleId,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final CallableId calleeCallableId,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Span span) {
|
||||
this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
this(kind, calleeModuleId, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final ModuleId calleeModuleId,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final CallableId calleeCallableId,
|
||||
final HostCallMetadata hostCall,
|
||||
@@ -121,36 +114,33 @@ public record IRBackendExecutableFunction(
|
||||
final Integer expectedArgSlots,
|
||||
final Integer expectedRetSlots,
|
||||
final Span span) {
|
||||
this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
this(kind, calleeModuleId, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final ModuleId calleeModuleId,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Span span) {
|
||||
this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
this(kind, calleeModuleId, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final ModuleId calleeModuleId,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Integer expectedArgSlots,
|
||||
final Integer expectedRetSlots,
|
||||
final Span span) {
|
||||
this(kind, calleeModuleId, calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
this(kind, calleeModuleId, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final CallableId calleeCallableId,
|
||||
final HostCallMetadata hostCall,
|
||||
@@ -160,23 +150,21 @@ public record IRBackendExecutableFunction(
|
||||
final Integer expectedArgSlots,
|
||||
final Integer expectedRetSlots,
|
||||
final Span span) {
|
||||
this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, label, targetLabel, expectedArgSlots, expectedRetSlots, span);
|
||||
this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, label, targetLabel, expectedArgSlots, expectedRetSlots, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final CallableId calleeCallableId,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Span span) {
|
||||
this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final CallableId calleeCallableId,
|
||||
final HostCallMetadata hostCall,
|
||||
@@ -184,29 +172,27 @@ public record IRBackendExecutableFunction(
|
||||
final Integer expectedArgSlots,
|
||||
final Integer expectedRetSlots,
|
||||
final Span span) {
|
||||
this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
this(kind, ModuleId.none(), calleeCallableName, calleeCallableId, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Span span) {
|
||||
this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
this(kind, ModuleId.none(), calleeCallableName, null, hostCall, intrinsicCall, null, null, null, null, span);
|
||||
}
|
||||
|
||||
public Instruction(
|
||||
final InstructionKind kind,
|
||||
final String calleeModuleKey,
|
||||
final String calleeCallableName,
|
||||
final HostCallMetadata hostCall,
|
||||
final IntrinsicCallMetadata intrinsicCall,
|
||||
final Integer expectedArgSlots,
|
||||
final Integer expectedRetSlots,
|
||||
final Span span) {
|
||||
this(kind, ModuleId.none(), calleeModuleKey, calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
this(kind, ModuleId.none(), calleeCallableName, null, hostCall, intrinsicCall, null, null, expectedArgSlots, expectedRetSlots, span);
|
||||
}
|
||||
|
||||
public Instruction {
|
||||
@@ -216,7 +202,6 @@ public record IRBackendExecutableFunction(
|
||||
if (!calleeModuleId.isNone()) {
|
||||
calleeModuleId.getIndex();
|
||||
}
|
||||
calleeModuleKey = calleeModuleKey == null ? "" : calleeModuleKey;
|
||||
calleeCallableName = calleeCallableName == null ? "" : calleeCallableName;
|
||||
label = label == null ? "" : label;
|
||||
targetLabel = targetLabel == null ? "" : targetLabel;
|
||||
|
||||
+12
-30
@@ -21,7 +21,7 @@ class IRBackendExecutableContractTest {
|
||||
void callInstructionMustRequireCategorySpecificMetadata() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_HOST,
|
||||
"",
|
||||
ModuleId.none(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
@@ -29,7 +29,7 @@ class IRBackendExecutableContractTest {
|
||||
|
||||
final var callFunc = new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
"app/main",
|
||||
ModuleId.none(),
|
||||
"foo",
|
||||
new CallableId(7),
|
||||
null,
|
||||
@@ -42,7 +42,6 @@ class IRBackendExecutableContractTest {
|
||||
void functionContractMustRejectInvalidSlotAndSpanBounds() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app",
|
||||
"main",
|
||||
new CallableId(1),
|
||||
10,
|
||||
@@ -56,7 +55,6 @@ class IRBackendExecutableContractTest {
|
||||
|
||||
final var thrown = assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app",
|
||||
"main",
|
||||
new CallableId(1),
|
||||
0,
|
||||
@@ -74,7 +72,7 @@ class IRBackendExecutableContractTest {
|
||||
void instructionContractMustRejectMixedMetadataKinds() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||
"app/main",
|
||||
ModuleId.none(),
|
||||
"foo",
|
||||
new CallableId(1),
|
||||
new IRBackendExecutableFunction.HostCallMetadata("gfx", "draw", 1, 0, 0),
|
||||
@@ -93,7 +91,7 @@ class IRBackendExecutableContractTest {
|
||||
void jumpAndLabelContractMustRequireNames() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.LABEL,
|
||||
"",
|
||||
ModuleId.none(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
@@ -106,7 +104,7 @@ class IRBackendExecutableContractTest {
|
||||
|
||||
assertThrows(IllegalArgumentException.class, () -> new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.JMP,
|
||||
"",
|
||||
ModuleId.none(),
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
@@ -125,7 +123,6 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
"entry",
|
||||
new CallableId(0),
|
||||
0,
|
||||
@@ -137,21 +134,18 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.HALT,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(2),
|
||||
"app/main",
|
||||
"aux",
|
||||
new CallableId(0),
|
||||
11,
|
||||
@@ -163,14 +157,12 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef("aux", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
@@ -213,7 +205,6 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
"app/main",
|
||||
"entry",
|
||||
new CallableId(0),
|
||||
0,
|
||||
@@ -225,20 +216,18 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef("entry", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1)));
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(2),
|
||||
"app/main",
|
||||
"aux",
|
||||
new CallableId(0),
|
||||
11,
|
||||
@@ -250,13 +239,12 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
new IRBackendExecutableFunction.IntrinsicCallMetadata("core.color.pack", 1, new IntrinsicId(0)),
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef("aux", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new IntrinsicReference("core.color.pack", 1)));
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
@@ -280,7 +268,6 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.empty(),
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(7),
|
||||
"app/main",
|
||||
"main",
|
||||
new CallableId(0),
|
||||
10,
|
||||
@@ -292,13 +279,12 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
instructionSpan)),
|
||||
functionSpan)),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new CallableSignatureRef("app/main", "main", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef("main", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
@@ -323,7 +309,6 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(1),
|
||||
new ModuleId(0),
|
||||
"app:mod/a",
|
||||
"entry",
|
||||
new CallableId(0),
|
||||
0,
|
||||
@@ -335,14 +320,13 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "a"))),
|
||||
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/a", "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "entry", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
final var fileB = new IRBackendFile(
|
||||
new FileId(2),
|
||||
@@ -350,7 +334,6 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction(
|
||||
new FileId(2),
|
||||
new ModuleId(0),
|
||||
"app:mod/b",
|
||||
"aux",
|
||||
new CallableId(0),
|
||||
6,
|
||||
@@ -362,14 +345,13 @@ class IRBackendExecutableContractTest {
|
||||
ReadOnlyList.from(new IRBackendExecutableFunction.Instruction(
|
||||
IRBackendExecutableFunction.InstructionKind.RET,
|
||||
"",
|
||||
"",
|
||||
null,
|
||||
null,
|
||||
Span.none())),
|
||||
Span.none())),
|
||||
IRReservedMetadata.empty(),
|
||||
ReadOnlyList.from(new ModuleReference("app", ReadOnlyList.from("mod", "b"))),
|
||||
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "app:mod/b", "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.from(new CallableSignatureRef(new ModuleId(0), "aux", 0, "() -> unit")),
|
||||
ReadOnlyList.empty());
|
||||
|
||||
final var aggregator = IRBackend.aggregator();
|
||||
|
||||
Reference in New Issue
Block a user